Filtered Exception : Try Catch « Development « VB.Net Tutorial






Option Strict Off

Public Module Tester 
   Public Sub Main
      Dim a, b As Integer

      Try
         
         a = 0
         b = 0
         a = a/b
      Catch e As DivideByZeroException When a = 0
         Console.WriteLine("Division by zero error: " & _
                          "the first divisor must not be zero.")
      Catch e As DivideByZeroException When b = 0
         Console.WriteLine("Division by zero error: " & _
                           "the second divisor must not be zero.")
      Catch e As Exception
         Console.WriteLine("Error: " & e.Message)
      End Try
   End Sub
End Module
Error: Arithmetic operation resulted in an overflow.








7.5.Try Catch
7.5.1.Try Catch Exception
7.5.2.Catch Exception throwed from a Method
7.5.3.Catch specific Exception from a Method
7.5.4.Catch different Exception with multiple catch statements
7.5.5.Filtered Exception
7.5.6.Catch without Exception type
7.5.7.Catch custom exception