This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
.NET provides a hierarchy of exception classes ultimately derived from theException base class. However, if none of the predefined exceptions meet your needs, you can create your own exception class by deriving from theException class.
When creating your own exceptions, end the class name of the user-defined exception with the word "Exception", and implement the three common constructors, as shown in the following example. The example defines a new exception class namedEmployeeListNotFoundException
. The class is derived from theException base class and includes three constructors.
using System;public class EmployeeListNotFoundException : Exception{ public EmployeeListNotFoundException() { } public EmployeeListNotFoundException(string message) : base(message) { } public EmployeeListNotFoundException(string message, Exception inner) : base(message, inner) { }}
Public Class EmployeeListNotFoundException Inherits Exception Public Sub New() End Sub Public Sub New(message As String) MyBase.New(message) End Sub Public Sub New(message As String, inner As Exception) MyBase.New(message, inner) End SubEnd Class
Note
In situations where you're using remoting, you must ensure that the metadata for any user-defined exceptions is available at the server (callee) and to the client (the proxy object or caller). For more information, seeBest practices for exceptions.
Was this page helpful?
Was this page helpful?