Error object (Object/core)

An object that represents a custom error condition.

Availability:

ECMAScript edition - 3
JavaScript - 1.5
JScript - 5.0
Internet Explorer - 5.0
Netscape - 6.0
JavaScript syntax:-myError = new Error()
-myError = new Error(aNumber)
-myError = new Error(aNumber, aText)
Argument list:aNumberAn error number
aTextA text describing the error
Object properties:constructor, description, message, name, number, prototype
Object methods:toString()

This object is provided to create custom error codes for your application. The ECMA standard (edition 3) describes them as objects that are thrown as exceptions when a run-time error occurs.

These objects are passed as the first argument of the catch() function in a try ... catch structure where you can inspect them and deal with the error.

Example code:

   // Force an error condition

   myError = new Error(100, "My user defined error text")

   try

   {

      throw myError;

   }

   catch(anErr)

   {

      confirm(anErr.description);

   }

   finally

   {

      alert("Sorted");

   }

See also:catch( ... ), EvalError object, RangeError object, ReferenceError object, SyntaxError object, throw, try ... catch ... finally, TypeError object, URIError object

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
constructor1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a3 3 n/a n/a n/aDontEnum
description n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/aWarning
message1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/aWarning
name1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/a-
number1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a n/a n/a n/a-
prototype1.5 1.55.0 5.06.0 6.05.0 5.03.0 3.02.0 2.03 3 n/a n/a n/aReadOnly, DontDelete, DontEnum

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
toString()1.5 1.55.0 5.06.0 6.05.0 5.03.0 3.02.0 2.03 3 n/a n/a n/a-

Cross-references:

ECMA 262 edition 3 - section - 15.1.4.9

ECMA 262 edition 3 - section - 15.11.1

ECMA 262 edition 3 - section - 15.11.2