Inherits System.ApplicationException : Custom Exception « Development « VB.Net Tutorial






Imports System.Runtime.Serialization
public class Test
   public Shared Sub Main
        Try
            Throw New MyException("This is my Exception.")
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
   End Sub
End class


Public Class MyException
    Inherits System.ApplicationException
    Public Sub New()
        MyBase.New("This object has expired")
    End Sub
    Public Sub New(ByVal new_message As String)
        MyBase.New(new_message)
    End Sub
    Public Sub New(ByVal new_message As String, ByVal inner_exception As Exception)
        MyBase.New(new_message, inner_exception)
    End Sub
    Public Sub New(ByVal info As SerializationInfo, _
    ByVal context As StreamingContext)
        MyBase.New(info, context)
    End Sub
End Class
This is my Exception.








7.6.Custom Exception
7.6.1.Create Custom Exception class
7.6.2.Create your own Exception class by subclassing System.Exception
7.6.3.Demonstrating a user-defined exception class
7.6.4.Inherits System.ApplicationException