Creating and Using Custom Exceptions

The .NET Framework enables you to define custom exception classes. To keep your custom-defined Exception class consistent with the .NET exception-handling framework, Microsoft recommends that you consider the following when you design a custom exception class:

  • Create an exception class only if no exception class exists that satisfies your requirement.

  • Derive all programmer-defined exception classes from the System.ApplicationException class.

  • End the name of a custom exception class with the word Exception for example, MyOwnCustomException .

  • Implement three constructors with the signatures shown in the following code:

     public class MyOwnCustomException : ApplicationException {    // Default constructor    public MyOwnCustomException ()    {    }    // Constructor accepting a string message    public MyOwnCustomException (string message) : base(message)    {    }    // Constructor accepting a string message and an inner exception    // that will be wrapped by this custom exception class    public MyOwnCustomException(string message,        Exception inner) : base(message, inner)    {    } } 


MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
ISBN: 789729016
EAN: N/A
Year: 2005
Pages: 191

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