W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

Re: Constructible Exceptions

From: Cameron McCormack <cam@mcc.id.au>
Date: Sun, 25 Mar 2012 11:39:39 +1100
Message-ID: <4F6E694B.9030100@mcc.id.au>
To: Marcos Caceres <w3c@marcosc.com>
CC: public-script-coord <public-script-coord@w3.org>
Marcos Caceres:
> Yeah.. I kinda realised that after I sent the email… however…. how do you create one without first coercing an exception object out of the exception type you want? I had a go at trying to do it [1]… but I had to do the following for a DOMException:
> try {
>          //force an exception to be generated;
>          document.removeChild({})
>   } catch (e) {
>          //use it as the prototype
>       newException = Object.create(e)
> }
> //alias for the prototype, helps us populate the new object
> var proto = newException.__proto__
> //"shadow" the name property on the new object
> //Chrome claims these are writable, but they aint! :)
> props = Object.getOwnPropertyDescriptor(proto, "name");
> props.value = name;
> Object.defineProperty(newException, "name", props);

I'm not really sure what you're doing here.  Do you want to construct a 
new DOMException even though the implementation does not yet allow `new 

Note that you want to end up with an object whose prototype is 
DOMException.prototype, not a DOMException instance.  But before the 
underlying DOM implementation supports constructable DOMException 
objects you're not going to be able to create one just by using 
Object.create, and that's because things on DOMException.prototype 
expect the instance to be a platform exception object, and from the 
perspective of the DOM implementation your object you have created with 
Object.create() is not a platform exception object.
Received on Sunday, 25 March 2012 00:40:12 UTC

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