September 20, 2002 - Extracting Information from the Error Object
September 20, 2002 Extracting Information from the Error Object Tips: September 2002
Yehuda Shiran, Ph.D.
|
try...catch
statement example:
try {
throw new Error(35,"null object, call your vendor");
}
catch(e) {
print("e is: " + e)
print("e.number is: " + (e.number & 0xFFFF));
print("e.description is: " + e.description);
print("e.name is: " + e.name);
print("e.message is: " + e.message);
}
Notice the four properties of the Error
object: number
, description
, name
, and message
. The description
property is identical to the message
property. The duplication is for historic reasons, and from the need to comply with the ECMA standard. The name
property is Error
, and the number property is the number assigned to the object during construction.
Notice that we bit-anded the number
property with the 16-bit all-one word. The higher order word may contain different information such as the facility code. The Error
number
property is saved in the lower 16-bit word.
You should also take notice that Error
is not a .NET framework type. If you need to share your JScript .NET module with other languages, you'd better use the System.Exception
type.
Put the example above in a file, say error.js
, compile and run it. You should get the following Command Prompt window:
To learn more about exception handling, go to Column 118, JScript .NET, Part XII: Exception Handling.