W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2010

a more JavaScripty binding for exceptions

From: Cameron McCormack <cam@mcc.id.au>
Date: Sat, 18 Dec 2010 07:09:20 +1300
To: public-script-coord@w3.org
Message-ID: <20101217180920.GA31176@wok.mcc.id.au>
Currently specs tend to use DOMException (or some separate exception
type) with integer exception codes given by constants defined on the
exception.  This isn’t so great:

* it requires coordination for the exception codes used on a given

* it requires the spec defining the exception to be updated to add
  constants for the new codes

* it’s not very JavaScripty

Here is a proposal for changing this:

* IDL exceptions will be allowed to inherit from other exceptions

* exceptions not declared to inherit from another will inherit from
  the Error prototype in the JS binding

* new specs will define a new IDL exception for each exception to
  define, rather than using DOMException (or a single new exception
  type) and a number of exception codes
* in JS, each exception constructor function will take a single argument
  for the exception message, just like the built-in Error objects do

This approach would also make it easier to catch categories of
exceptions, if their hierarchy is defined that way; instead of checking
for various codes in an exception handler, you could do an instanceof

Existing, implemented specs that use exception codes would still have to
work.  We could think about migrating DOMException to multiple exception
types in Web DOM Core with something like this:

  exception DOMException {
    unsigned short code;

  exception HierarchyRequestError : DOMException { };
  exception NoModificationAllowedError : DOMException { }:
  // etc.

Comments welcome on this approach.

Cameron McCormack ≝ http://mcc.id.au/
Received on Friday, 17 December 2010 18:10:02 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:02 UTC