Catch custom exception : Try Catch « Development « VB.Net Tutorial






Public Class MyException
    Inherits System.Exception

    Sub New(ByVal Message As String)
        MyBase.New(Message)
    End Sub
End Class


Public Class Tester
    Public Shared Sub Main
        Try
            Console.WriteLine("About to generate custom exception")
            Throw (New MyException("** Custom Message **"))
        Catch Ex As MyException
            Console.WriteLine("Custom Exception thrown " & Ex.Message)
        End Try
    End Sub

End Class
About to generate custom exception
Custom Exception thrown ** Custom Message **








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