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...FinallyThe 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
Sponsored links
Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
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.
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!
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
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!
3 Months Free & No Setup Fees on ASP.NET 3.5/2.0 Hosting on Windows 2008/2003 Servers ? Click Here!
