Talk:Core JavaScript 1.5 Guide:Exception Handling Statements:try...catch Statement
From MDC
I was developing a portion of javascript code using multiple catch statements similar to the example:
try {
throw 'error';
} catch (e if (e == 'error')) {
// do something
} catch (e) {
// catch all
}
This code works perfectly fine using SpiderMonkey but does not work in JScript, I considered that the JScript developers had not followed ECMAScript specifications so I checked into it and it turns out that multiple conditional catch blocks are not defined in the specification. The correct ECMAScript compliant code would be:
try {
throw 'error';
} catch (e) {
if (e == 'error') {
// do something
} else {
// catch all
}
}
Perhaps a note or distinction should be made that the multiple catch block definition is an extension to ECMAScript and the alternative or compliant version be provided to help with compatibility.
- This is mentioned in the Reference, but please feel free to add it to this page too. Thanks. --Nickolay 12:57, 30 June 2006 (PDT)