Joy Online Manual

NAME
try...catch - Handle JavaScript errors

SYNOPSIS

try statement1 catch ([var] name) statement2

DESCRIPTION
Both  statement1 and  statement2 can be compound statements (blocks). If the execution of  statement1  results in a JavaScript error, the error message is assigned to the variable  name  and control proceeds to  statement2.  If statement1  executes without error,  statement2  is not executed at all.

The  statement2  can examine the error and take appropriate action, including reraising the error (or a different one) using throw. You can throw and catch any JavaScript value, not just strings.

EXAMPLE

js> try {
print(undefined)
}
catch (var e) {
print("caught: " + e)
}
caught: undefined is not defined

SEE ALSO

throw

Index