To define a custom exception class, make a class that inherits from Exception. To give developers who use the class the most flexibility, provide four constructors that delegate their work to the Exception class’s corresponding constructors.
The following code shows the InvalidWorkAssignmentException class. The empty constructor passes the Exception class’s constructor a default error message. The other constructors simply pass their arguments to the Exception class’s other constructors.
Public Class InvalidWorkAssignmentException Inherits Exception Public Sub New() MyBase.New("This work assignment is invalid") End Sub Public Sub New(ByVal msg As String) MyBase.New(msg) End Sub Public Sub New(ByVal msg As String, ByVal inner_exception As Exception) MyBase.New(msg, inner_exception) End Sub Public Sub New(ByVal info As SerializationInfo, _ ByVal context As StreamingContext) MyBase.New(info, context) End Sub End Class