Joy Online Manual

NAME
NS_DURING...NS_HANDLER - Exception handling

SYNOPSIS

NS_DURING
statements1
NS_HANDLER
statements2
NS_ENDHANDLER

NS_VALUERETURN(expr, type)
NS_VOIDRETURN

DESCRIPTION
This is an Objective-C compatible alternative to the JavaScript try...catch statement. If the execution of  statements1  results in an Objective-C exception or JavaScript error, control will proceed to statements2 where the variable localException will contain an NSException object.

To maintain compatibility with Objective-C you should use one of the special forms NS_VALUERETURN or NS_VOIDRETURN instead of plain return when you want to leave the currently executing function or method from between NS_HANDLER and NS_ENDHANDLER.

EXAMPLE

js> NS_DURING
[NSException raise: "Test" format: "some error occurred"]
NS_HANDLER
print("*** " + [localException name] + ": " + [localException reason])
NS_ENDHANDLER
*** Test: some error occurred


Index