ES4 draft: Error classes

Ash Berlin ash_es4 at firemirror.com
Fri Mar 7 02:18:24 PST 2008


On 7 Mar 2008, at 08:02, Michael Daumling wrote:

> This may sound like a stupid question, but...
>
> Adding file and line info to an Error instance seems to be a good  
> thing.
> Should the standard include two read-only properties "fileName" and
> "line" that an implementation may choose to fill in during  
> construction,
> and that return, say, the empty string and -1 if not supported?
>
> SpiderMonkey and ExtendScript both support these properties.
>
> Michael

I'm for this, and on a similar tact make it easier to subclass error  
to create custom user Error classes. Currently in Spidermonkey you  
have to jump through the following hoops to get an Error subclass with  
filename and linenumber properties:

http://groups.google.com/group/mozilla.dev.tech.js-engine/browse_thread/thread/af195c5aafbfcb32

I forget all the problems, but from memory the main one is that:

MyError = function() {};
MyError.prototype = Error.prototype;

Doesn't do what you'd expect. And doing

MyError.prototype = new Error();

Is no good since then the filename and linenumber will be of that  
line, not where you create the MyError instance.

Ash
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080307/c5d347f0/attachment-0002.html 


More information about the Es4-discuss mailing list