What is Try- Catch –Finally Exception Handling?

Exceptions are Runtime errors that occur when an unexpected process causes the program to abort. Such kind of situations can be kept at bay using Exception Handling. By looking for potential problems in the code / entity life cycle, we can handle most of the errors that may encountered. As a result the application to continue to run without being dogged by errors. VB.NET supports Structured exception handling by using Try...Catch...Finally

The following code sample demonstrates how to use Try-Catch-Finally exception handling.

Module Module1
Sub Main()
Dim a=0, b=1, c As Integer
Try
c=b / a
'the above line throws an exception
System.Console.WriteLine("C is " & c)
Catch e As Exception
System.Console.WriteLine(e)
'catching the exception
End Try
System.Console.Read()
End Sub
End Module


The output of the above code displays a message stating the exception. The reason for the exception is because any number divided by zero is infinity.

Written by Sandeep Mogulla, Webmaster at www.startvbdotnet.com

Index

 
Printer friendly version of the FAQ-VBNET-Exception-Handling page


Sponsored links

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Villanova University Six Sigma & IT Certificate Programs
100% Online programs in Six Sigma, IS Security, CISSP Prep, Business Analysis, Proj. Mgmt. and more!
SFTP components for .NET
Add complete SSH and SFTP support to your .NET framework application
3 Months Free - ASP.NET Web Hosting
3 Months Free & No Setup Fees on ASP.NET 3.5/2.0 Hosting on Windows 2008/2003 Servers ? Click Here!

Advertisement



Free Magazine

Free Magazines
eWeek The essential technology information source for builders of e-business.... subscribe now

Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.