September 19, 2002 - Creating and Throwing Error Object Exceptions
September 19, 2002|
Creating and Throwing Error Object Exceptions
Tips: September 2002
Yehuda Shiran, Ph.D.
catchblock, to be caught by a
catchblock at the same or higher level of
try...catchnesting. For example, you can throw the error message
"Error 325 from inner try block"as an exception.
But JScript .NET supports a more structured exception: the
Error object. An
Error object is thrown by the system whenever there is a run-time error. You can throw your own
Error objects, and thus keep all exceptions of the
Error type. You create
Error objects with the
function Error([number : Number [, description : String ]])
number is a numeric value assigned to the exception. It is optional.
description is a brief string that describes the exception. It is optional.
You can create a new
Error object, populate it, and throw it, all in the same statement. For example:
To learn more about exception handling, go to Column 118, JScript .NET, Part XII: Exception Handling.
throw new Error(35,"null object, call your vendor");