Forum Discussion
Philip_Baird
13 years agoCommunity Expert
Hi Will, here is an example of how I work-around this issue, instead of code throwing exceptions, I utilise JScripts loose typing by returning Exceptions instead
/**
* Demonstrates the Exception handling pattern to work around the Script Unit
* isoloation issue where the method that raises the exception would normally
* return a value
* @method demoPatternNormallyReturnValue
* @author Phillip Baird
* @date 01/07/2013
*/
function demoPatternNormallyReturnValue() {
var result; // Result of the method call
try {
// Call method that will return Exception
result = exceptionRaiser.raiseExcepionWithReturn( true );
// Check to see if a result was returned. The check is done for the generic
// BaseException as a catch all, with more specific type checking done in the
// catch block
if( result && ( result instanceof exceptions.BaseException ) ) {
throw result;
}
Log.Message( "No Exception " + result ); // No exception raised
} catch( exObj ) {
// Check for and handle specific exception types
if( exObj instanceof exceptions.CreateFolderException ) {
Log.Message( exObj.exceptionString() );
} else {
// Handle unknown exception type
Log.Message( "Unknown Exception" );
}
}
}
I have an Exception base prototype which allows me to check for instances of specific Exceptions.
It's a little un-wieldly but seems to work ok for my purposes