spacer
Yehuda Shiran September 13, 2002
Processing in the try, catch, and finally Blocks
Tips: September 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies

The try...catch...finally statement in JScript .NET lets you handle the errors that may occur in the try block. If an error occurs in the try block, program control is passed to the catch block. The value passed to the catch block as a parameter is the value of the error that occurred in the try block. If no error occurs, the catch block is not executed. For errors that you don't handle in the catch block, JScript .NET provides its normal error message to the user, as if there was no error handling. But remember, avoid showing system errors to the user, as they may give the impression of buggy and sloppy coding.

After all statements in the try block have been executed and any error processing has been completed in the catch block, the finally block is unconditionally executed. The code inside the finally block is always executed. Even if the catch block re-throws the error or if a return statement occurs inside the catch or try blocks, the finally block is guaranteed to run. The only exception is when an unhandled error occurs; in this case, the system processes this run-time error by printing a message to the user and quitting from the JScript .NET application.

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 >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji