A few questions and suggestions.
Brendan Eich
brendan at mozilla.org
Sun Apr 29 20:38:54 PDT 2007
On Apr 29, 2007, at 8:24 PM, Michael Daumling wrote:
> Hi Thiago,
>
> Just a quick word about this:
>
>>> *** Exceptions
>>>
>>> Currently, I really miss the ability to catch exceptions given it's
> type. In the new ES spec, will the following code be possible?
>
>>> Try { ... }
>>> catch(e : TypeError) { ... }
>>> catch(e : ReferenceError) { ... }
>
> The correct syntax is in today's SpiderMonkey implementation already,
> and it goes like this:
>
> try {...}
> catch (e if e instanceof TypeError) { ... }
>
> In short: JavaScript supports conditional catches, and you can, of
> course, check the type of an error this way.
Actually, that's a SpiderMonkey extension proposed for ES3 and
rejected. We favored it instead of what ES3 forces you to do:
try { ... }
catch (e) {
if (guard1) ...
else if (guard2) ...
...
else if (guardN) ...
else throw e
}
where the guardN expressions involve e somehow. We observed that it's
easy to forget to rethrow on mismatch.
ES4 has catch (e : type) ... clauses, as Thiago wants.
/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20070429/e069875a/attachment-0002.html
More information about the Es4-discuss
mailing list