Forum Discussion
There was a post on SQA Forums several years ago about how to handle this issue.
Essentially, it is a 4 step process. Overall, it is awkward and a bit ugly, but it does
work.
1. Create an exception class that can be used to percolate exceptions up the call stack.
function CustomException (value1, value2)
// Actually, this class can take mutiple values, not just strings.
// Unfortunately, I can't share our implementation.
{
this.message = value1
this.description = value2
}
2. Use try/catch blocks to translate exceptions into return values of your exception class.
function Test1 ()
{
var returnValue = null;
try
{
// test case goes here.
}
catch (exception)
{
returnValue = new CustomException (exception);
}
return (returnValue);
}
3. Add a CheckResult () wrapper function in every script unit and use it when calling other methods.
function BiggerTest ()
{
CheckResult (Test1 ())
}
function CheckResult (value)
{
if (value instanceof CustomException)
{
throw value;
}
else
{
return (value);
}
}
4. Deal with the exceptions at the appropriate level, usually at the level of the Main () function.
Happy Testing,
Glen Accardo