Custom Exception Classes


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 




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net