Conditional catch clause
brendan at mozilla.com
Thu Dec 20 12:38:03 PST 2012
John J Barton wrote:
> Depending on the design, this could be anywhere from "only
> errors raise exceptions" to "developers must supply a
> algorithm to decide". Languages with a centrally controlled
> type system (I have in mind Java) provide a relatively simple
> way to separate these exceptions.
> And how is this relevant? I'm not snarking back. JS != Java.
> Java is one example of a language that supports non-error uses of the
> try/catch exception mechanism. Part of that support includes a way for
> debuggers to distinguish errors uses from non-error uses. Encouraging
> additional non-error use
Again, I object. StopIteration is not "encouraging additional non-error
[uses of try/catch]" outside of specialized, written-by-experts
libraries such as http://taskjs.org/.
The exceptions-are-not-all-errors cat is out of the bag. You don't seem
to agree but you haven't rebutted directly. I cry foul.
> separate them from error uses
Again, without a type system, how?
Testing catch (e if e instanceof Error) was an explicit intended use of
catch guards from the ES3 days. With standard catch you would write an
if-else chain and remember to re-throw in final else. This is quite
doable now, so what's the problem? Note that DOMException instanceof
Error per http://www.w3.org/TR/WebIDL/#es-exceptions.
Yes, instanceof does not work cross-frame. This has been debated on
es-discuss a lot. For same-realm uses, it suffices, as people here have
pointed out recently. Exception catching may favor same-realm, I'm not
sure. But this is a separate issue.
> will make features like onExceptionUnwind tedious for developers to use.
This is just the lowest tier of the API and we're not done yet.
To be frank, I think your frustration is perfectly understandable, but
not grounds for general exhortations or judgments against particulars
(StopIteration) that are not relevant (for-of handles outside of
specialized taskjs settings), or at the very least not decisive in light
of precedent (instanceof Error testing). Anyway, I hope to have shed
some light here. How'd I do?
More information about the es-discuss