spacer
Yehuda Shiran September 19, 2002
Creating and Throwing Error Object Exceptions
Tips: September 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

The simplest form of an exception is the string. You just throw a string from a try or a catch block, to be caught by a catch block at the same or higher level of try...catch nesting. 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 Error constructor:

  function Error([number : Number [, description : String ]])
where:

  • 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:

  throw new Error(35,"null object, call your vendor");
To learn more about exception handling, go to Column 118, JScript .NET, Part XII: Exception Handling.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint