Re: [WebIDL] Exceptions

On Wed, Jul 6, 2011 at 9:04 PM, Ian Hickson <> wrote:
> On Wed, 6 Jul 2011, Aryeh Gregor wrote:
>> The thing I don't like about this proposal is that it encourages authors
>> to use "e instanceof IndexSizeError" or similar.  This will work 98% of
>> the time and then fail in an extremely mysterious way when multiple
>> globals are involved.  All you need is the exception to be thrown by
>> something in an iframe for whatever reason.
> I'm also skeptical of this. The platform uses DOMException almost
> everywhere, and I really don't see what's wrong with that.

It's a pain since it forces us to try to coordinate codes across
multiple specifications, working groups and standards organizations.
So far this has failed resulting in multiple specifications defining
their own exception types with overlapping codes, forcing people to
check both interface and code. I strongly suspect there's tons of
"buggy" JS code out there that doesn't do this correctly and just
checks the code.

So while in theory using codes to distinguish could work, in practice it hasn't.

And even if this coordinating somehow started magically working, it
still means that exceptions thrown by the DOM needs to be checked
differently than exceptions thrown by ES. So you'll end up having to

switch (ex.code) {
   switch ( {
     case "TypeError":

Lastly, the syntax:
if ( === "HierarchyRequestError") { ... }
is a lot easier on the eyes than:
if (ex.code === DOMException.HIERARCHY_REQUEST_ERR) { ... }

/ Jonas

Received on Thursday, 7 July 2011 18:29:14 UTC