ES4 draft: Error classes

Ash Berlin ash_es4 at
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:

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.

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Es4-discuss mailing list