Private Sub SEHTest()
Dim X1 As Long, X2 As Long, X3 As Long
    Try
        'Any error that occurs inside the try...end try block
        'should be caught by the error handler...
        Dim sResponse As String
        WriteLine("Enter an integer number for the numerator")
        sResponse = ReadLine()
        X1 = X1.Parse(sResponse)
        WriteLine("Enter an integer number for the denominator")
        sResponse = ReadLine()
        X2 = X2.Parse(sResponse)
        WriteLine("You entered: " & X1 & ", " & X2)
        'we can, if we want, "cause" our own specific errors...
        If X2 = 0 Then Throw New DivideByZeroException()
        X3 = X1 \ X2
        WriteLine("Division resulted in: " & X3)
    Catch DivZero As System.DivideByZeroException
        'catch a specific error: divide by zero is the most likely to occur
        WriteLine("Divide by 0 was detected...")
        MsgBox("An Exception was caught: " & vbCr & DivZero.ToString)
    Catch Err As System.Exception
        'if it wasn't a divide by zero then we have to assume something else, and handle a default
        'error type...
        WriteLine("An Exception was thrown!!")
        MsgBox("An Exception has been caught:" & vbCr & Err.ToString & vbCr & vbCr & _
Err.StackTrace, MsgBoxStyle.Critical, "Error") End Try End Sub