Check Err.Number When there is an Error : Err Number « Development « VB.Net






Check Err.Number When there is an Error

Check Err.Number When there is an Error
Imports System

Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim X As Integer

        ' Try to calculate X.
        On Error Resume Next
        
        X = CalculateValue()
        
        Select Case Err.Number
            Case 0 ' No error. Do nothing.
            Case 11 ' Divide by zero. Set a default value.
                X = 1000
            Case Else ' Unexpected error. Tell the user.
                Console.WriteLine("Error calculating X." & vbCrLf & Err.Description)
                Exit Sub
        End Select

        Console.WriteLine("X = " & X)

    End Sub
    
    Shared Private Function CalculateValue() As Integer
        Return 1 \ Integer.Parse("0")
    End Function

End Class

           
       








Related examples in the same category

1.On Error Resume NextOn Error Resume Next