ErrorNN 6 IE 5(Win) ECMA 3  

  

Browsers that implement try/catch exception handling automatically create an instance of the Error object whenever an error occurs during script processing. You can also create an Error object instance that you explicitly throw. The catch portion of the try/catch construction receives the Error object instance as a parameter, which scripts can examine to learn the details of the error, as exposed by the object's properties.

 
Properties
 
constructordescriptionfileNamelineNumber
messagenamenumberprototype
 
Methods
 
toString( )
 
Creating an Error Object
 
var myError = new Error("errorMessage");
constructorNN 6 IE 5(Win) ECMA 3  

Read/Write  

Provides a reference to the function that created the instance of an Error objectthe native Error( ) constructor function in browsers.

 
Example
 
if (myVar.constructor == Error) {
    // process native string
}
 
Value

Function object reference.

descriptionNN n/a IE 5(Win) ECMA n/a  

Read/Write  

Provides a plain-language description of the error, frequently the same as appears in the IE script error dialog. Use the newer message property if possible.

 
Example
 
if (myError.description.indexOf("Object expected") != -1) {
    // handle "object expected" error
}
 
Value

String.

fileNameNN 6 IE n/a ECMA n/a  

Read/Write  

Specifies the URL of the page in which the script error occurred. This information appears in the JavaScript Console window for each reported error.

 
Example
 
var sourceFile = myError.fileName;
 
Value

URL string.

lineNumberNN 6 IE n/a ECMA n/a  

Read/Write  

Specifies the number of the line in the source code where the current script error occurred. This information appears in the JavaScript Console window for each reported error.

 
Example
 
var errorLine = myError.lineNumber;
 
Value

Number in string format.

messageNN 6 IE 5.5(Win) ECMA 3  

Read/Write  

Provides a plain-language description of the error. There is no standard for the format or content of such messages.

 
Example
 
if (myError.description.indexOf("defined") != -1) {
    // handle error for something being undefined
}
 
Value

String.

nameNN 6 IE 5.5(Win) ECMA 3  

Read/Write  

This is a string that sometimes indicates the type of the current error. The default value of this property is Error. But the browser may also report types EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, and, if supported by the browser, a specific W3C DOM error type.

 
Example
 
if (myError.name == "SyntaxError") {
    // handle syntax error
}
 
Value

String.

numberNN n/a IE 5(Win) ECMA n/a  

Read/Write  

Provides a number corresponding to an IE error. You must apply binary arithmetic to the value to derive a meaningful number. Use:

var errNum = ErrObj.number& x0FFFF; 

Then compare the result against Microsoft's numbered listing at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsmscRunTimeErrors.asp.

 
Example
 
var errNo = myError.number;
 
Value

Number.

prototypeNN 6 IE 5(Win) ECMA 3  

Read/Write  

This is a property of the static Error object. Use the prototype property to assign new properties and methods to future instances of a Error object created in the current document. See the Array.prototype property description for examples.

 
Example
 
Error.prototype.custom = true;
 
Value

Any data, including function references.

toString( )NN 6 IE 5(Win) ECMA 3  

  

Returns a string representation of the object, but the values differ between browser families. IE returns [object Error], while Netscape 6 returns a concatenation of the name and message properties.

 
Parameters

None.

 
Returned Value

String.