Joy Online Manual
Exception Handling
When you call Objective-C methods or C functions from JavaScript, Joy will automatically catch any NSExceptions that occur and report them. If the NSException name is equal to ItkObjCJSErrorException (this can happen if the Objective-C method or C function itself called some JavaScript), Joy will extract the original JavaScript error out of the reason and userInfo and re-report it. Else, if a try...catch statement is currently in effect, the NSException object will be assigned to the catch variable and execution will continue in the error handler. If there is no active try...catch, the exception will be converted to a string and reported as a JavaScript error message. When you call JavaScript code from Objective-C and JavaScript errors occur, Joy will convert them to a NSException with name ItkObjCJSErrorException, a reason equal to the error message (if there are multiple errors, they are joined together with newlines), and a userInfo that is an NSArray of NSDictionaries, one for each error, with members corresponding to the fields of the JSErrorReport structure (see jsapi.h). If the JavaScript code causes an Objective-C exception, Joy will raise it only after the JavaScript calling stack has been unwound. The net effect of all these seemingly complex rules is that you can catch JavaScript errors from JavaScript, or Objective-C exceptions from Objective-C, without having to care about any intervening Objective-C or JavaScript code on the calling stack. |