ARTICLE

Exception Handling in visual Basic.NET

Posted by Manish Tewatia Articles | Visual Basic Language July 01, 2010
In this small article you will learn how to use Exception Handling in visual Basic.NET
 
Reader Level:

Exception handling isa technique of handling a situation which is occur at the run time when program abort without execution and the cause of that situation is called exception.

 Exception can be handled by two ways in VB.NET .

1.Structured exception handling.

2. Unstructured exception handling.

Hear I am going to tell about the structured exception handling using : Try….Catch….Finally.

Example:

Module Module1

    Sub Main()
        Dim a = 0, b = 1, c As
Integer
       
Try
            c = b / a
            Console.WriteLine("C is " & c)
        Catch e As
Exception
            Console.WriteLine(e)
            Console.WriteLine("0 can't be divided by any number")
            Console.ReadLine()
        End
Try

    End Sub

 End Module

OUTPUT:

1.gif

In this code a numberis divided by zero which result is infinity. This error is thrown by Try Block and Catch block shows the exception after catching it.


CONCLUSION:

This example helps you to understand how exception occurs than thrown and than catch and shows the exception at the run time.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor