number Property 

Returns or sets the numeric value associated with a specific error.


object.number

object

Any instance of the Error object.

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. To read off the actual error code, use the & (bitwise And) operator to combine the number property with the hexadecimal number 0xFFFF.

The following example causes an exception to be thrown, and displays the error number.

function getAge(age) {
   if(age < 0)
      throw new Error(100)
   print("Age is "+age+".");
}

// Pass the getAge an invalid argument.
try {
   getAge(-5);
} catch(e) {
// Extract the error code from the error number.
   print(e.number & 0xFFFF)
}

The output of this code is:

100
Show: