Vb.Net-Informations.com

  VB.NET On Error GoTo




   Categories

    HOME
    VB.NET
    CSHARP

 
   














VB.NET On Error GoTo

On Error GoTo statements is an example of Vb.Net's Unstructured Exception Handling . VB.NET has two types of Exception handling . Structured Error Handling and Unstructured Error handling . VB.NET using Try..Catch statement for Structured Error handling and On Error GoTo statement is using for Unstructured Error handling.

Error GoTo redirect the flow of the program in a given location.

On Error Resume Next - whenever an error occurred in runtime , skip the statement and continue execution on following statements.

Take a look at the following program

VB.NET Source Code

  Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        Dim result As Integer
        Dim num As Integer
        num = 100
        result = num / 0
        MsgBox("here")
    End Sub

End Class

when u execute this program you will get error message like " Arithmetic operation resulted in an overflow "

See the program we put an On Error GoTo statement


         VB.NET Source Code Download           Print Source Code
         VB.NET On Error GoTo - Download
        
VB.Net Tutorial

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        On Error GoTo nextstep
        Dim result As Integer
        Dim num As Integer
        num = 100
        result = num / 0
nextstep:
        MsgBox("Control Here")
    End Sub
End Class

When you execute the program you will get the message box "Control Here" . Because the On Error statement redirect the exception to the Label statement.

VB.NET Language Basics Related Contents
*     VB.NET data types
*     VB.NET Implicit conversion and Explicit Conversion
*     VB.NET Access Specifiers
*     VB.NET Exceptions
*     VB.NET Option Explicit
*     VB.NET Option Strict

VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial with source code
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
Search here for more CSharp Source Code :

  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved