Custom Exceptions


You can derive your own custom exception classes from the System.ApplicationException class, as shown in the following example. By convention, the name of an exception class should end with Exception. Also by convention, you should provide at least the first three constructors shown here.

  Imports System.Runtime.Serialization Public Class ObjectExpiredException     Inherits System.ApplicationException     ' No parameters. Use a default message.     Public Sub New()         MyBase.New("This object has expired")     End Sub     ' Set the message.     Public Sub New(ByVal new_message As String)         MyBase.New(new_message)     End Sub     ' Set the message and inner exception.     Public Sub New(ByVal new_message As String, _      ByVal inner_exception As Exception)         MyBase.New(new_message, inner_exception)     End Sub     ' Include SerializationInfo object and StreamingContext objects.     Public Sub New(ByVal info As SerializationInfo, _      ByVal context As StreamingContext)         MyBase.New(info, context)     End Sub End Class 

For a little more information on custom exception handling, see the section “Custom Exception Classes” in Appendix N. For more detailed information, see the online documentation for topics such as “Designing Custom Exceptions” (msdn2.microsoft.com/en-us/library/ms229064.aspx) and “Design Guidelines for Exceptions” (msdn2.microsoft.com/en-us/library/ms229014.aspx), or search the Web for articles such as “Custom Exceptions in VB 2005” by Josh Fitzgerald (www.developer.com/net/vb/ article.php/3590931).




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