What browsers support Conditional catch clauses?
On MDN try...catch you can find Conditional catch clauses as Non-standard feature.
try {
myroutine(); // may throw three exceptions
} catch (e if e instanceof TypeError) {
// statements to handle TypeError exceptions
} catch (e if e instanceof RangeError) {
// statements to handle RangeError exceptions
} catch (e if e instanceof EvalError) {
// statements to handle EvalError exceptions
} catch (e) {
// statements to handle any unspecified exceptions
logMyErrors(e); // pass exception object to error handler
}
Note: This functionality is not part of the ECMAScript specification.
It's supported by any modern browsers?
Google Chrome's console returned Uncaught SyntaxError: Unexpected token if
Or shoud I use:
try {
myroutine(); // may throw three exceptions
} catch (e) {
if(e instanceof TypeError) {
// statements to handle TypeError exceptions
}
else if(e instanceof RangeError) {
// statements to handle RangeError exceptions
}
else if(e instanceof EvalError) {
// statements to handle EvalError exceptions
}
else {
// statements to handle any unspecified exceptions
logMyErrors(e); // pass exception object to error handler
}
}