Javascript Error Objects


Error Object

number Property

Description

Returns or sets the numeric value associated with a specific error. The Error object's default property is number.

Syntax

object.number [= errornumber]

The number property syntax has these parts:

Part Description
object Any instance of the Error object.
errornumber An integer representing an error.
Remarks

An error number is a 32-bit value. The upper 16-bit word is the facility code, while the lower word is the actual error code.

The following example illustrates the use of the number property:

try {
  x = y         		             // Cause an error.
}
catch(var e) {                         // Create local variable e.
  document.write(e)                    // Prints "[object Error]".
  document.write(e.number>>16 & 0x1FFF)// Prints 10, the facility code.
  document.write(e.number & 0xFFFF)    // Prints 5009, the error code.
  document.write(e.description)        // Prints "'y' is undefined".
}

description Property

Description

Returns or sets the descriptive string associated with a specific error.

Syntax

object.description [= stringexpression]

The description property syntax has these parts:

Part Description
object Any instance of an Error object.
stringexpression A string expression containing a description of the error.
Remarks

The description property contains the error message string associated with a specific error. Use the value contained in this property to alert a user to an error that you can't or don't want to handle.

The following example illustrates the use of the description property:

try {
  x = y                              // Cause an error.
}
catch(var e {                        // Create local variable e.
  document.write(e)                  // Prints "[object Error]".
  document.write((e.number & 0xFFFF))// Prints 5009.
  document.write(e.description)      // Prints "'y' is undefined".
}