spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column118


JScript .NET, Part XII: Exception Handling

KRONOS Technical Analyst
Professional Technical Resources
US-OR-Portland

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

The Error Object

So far, we've thrown strings as exceptions. We threw "Error 325 from inner try block" for example. 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");

Here is a 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:


Next: A Final Word

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: September 9, 2002
Revised: September 9, 2002

URL: http://www.webreference.com/js/column118/6.html