VB.Net by API/Microsoft.VisualBasic/Err

Материал из VB Эксперт
Перейти к: навигация, поиск

Err.Number

   
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