spacer
Yehuda Shiran October 18, 2000
Creating Error Messages
Tips: October 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

One of the messiest problems in every software project is handling and managing error messages. Each developer tends to create his or her own style for conveying them to the confused user. If conventions and methodology are not in place in the beginning of the project, it is very unlikely that members of the team will fix it at the end. Some programming languages provide infrastructure for creating, managing, and displaying error messages. JavaScript's support includes an object and properties. The Error object is constructed with two arguments:

  • number. The error number. Zero, if no number is provided.
  • description. A string that describes the error. Empty, if no description is provided.

The following statement creates an instance of the Error object:

var myError = Error(31, "Fatal error has been detected. Failed in a consistency check. Please call your vendor.");

The Error object supports two properties, matching the arguments above: number and description. You can both read as well as set them. The following code prints a message, consisting of the error number and its description:

alert("Error No. " + myError.number + ":" + "\n" + myError.description);

We have added the constructor above to this tip, and now you can try and print both properties of myError.


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Installing and Using Meeplace, the Business Review CMS · Sending an HTML and Plain Text E-newsletter with ASP.NET, Part 2 · Create Multilingual Web Sites with Windows Unicode Fonts
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Eight Reasons Why Oracle's Acquisition of Sun isn't All Bad · The New Threat to Data Center Security: The Underground Economy · Buyers' Guide: Choosing a Payment Gateway Provider