Core JavaScript 1.5 Reference:Global Objects:Error:toString
From MDC
Contents |
[edit] Summary
Returns a string representing the specified Error object
[edit] Syntax
error.toString()
[edit] Parameters
None.
[edit] Description
The Error object overrides the Object.prototype.toString method inherited by all objects. According to ECMA-262, implementations are free to decide the behavior of this method. SpiderMonkey joins string representations of the name and message properties with a colon and a space separating the two. If the string representation of either of these two properties is an empty string, this method simply returns the string representation of the property that has a non-zero length. If both properties' string representations are empty strings, this method returns an empty string.
Note that when creating a string representation of the name and message properties, this method does not invoke those properties' toString methods. If the value in either of these properties is not already a string, this method will behave as if that property contained an empty string.
[edit] Example
var e = new Error("fatal error");
e.toString(); // returns "Error: fatal error"
e.name = undefined;
e.toString(); // returns "fatal error"
e.message = undefined;
e.toString(); // returns ""
e.name = "Error";
e.toString(); // returns "Error"