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

[DOM4] Constructor for DOMException?

From: Marcos Caceres <marcosscaceres@gmail.com>
Date: Tue, 21 Feb 2012 12:46:08 +0000
To: public-webapps <public-webapps@w3.org>
Message-ID: <1FA9117FC18746609A1E70106B83AA2C@gmail.com>
Hi,  
I'm currently trying to implement a spec using ECMAScript. Unfortunately, I have a bunch of DOMExceptions that can't be thrown cleanly because there is no way to instantiate a DOMException through ECMAScript (new DOMException(...) returns a "TypeError: Illegal constructor" in browsers).   

An example of a conformance requirement I'm trying to implement:  

"When instructed to throw a security exception, the user agent throws a "SecurityError" DOMException, with its message set to "Access to 'scheme x://' is not allowed.", where x is replaced by the name of the disallowed scheme."

I've noticed that other developers have come up against the same issue, and have found some nasty workarounds (coercing an exception from some other code, and then throwing that instead [1]).  

So… given that one can fake create a DOMException, and unless there is a valid reason not to allow this that I don't know of…. It would be nice if DOMException just defined a public constructor. This would allow clean prototyping of various APIs in ECMAScript (and give us poor saps who don't know C a chance to implement some Web APIs :) ).  

[1] http://stackoverflow.com/questions/5136727/manually-artificially-throwing-a-domexception-with-javascript  
Received on Tuesday, 21 February 2012 12:46:42 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:50 GMT