Information Technology Reference
In-Depth Information
class must end in “Exception”. You should always derive your exception
classes from the System.Exception class, or some other appropriate excep-
tion class. You will rarely add capabilities to this base class. The purpose of
different exception classes is to have the capability to differentiate the cause
of errors in catch clauses.
But don't take anything away from the exception classes you create, either.
The Exception class contains four constructors:
// Default constructor
public Exception();
// Create with a message.
public Exception( string );
// Create with a message and an inner exception.
public Exception( string , Exception );
// Create from an input stream.
protected Exception(
SerializationInfo , StreamingContext );
When you create a new exception class, create all four of these construc-
tors. Notice that the last constructor implies that your exception class must
be Serializable. Different situations call for the different methods of con-
structing exceptions. (If you choose to derive from a different exception
class, you should include all the appropriate constructors from that par-
ticular base class.) You delegate the work to the base class implementation:
[ Serializable ]
public class MyAssemblyException :
Exception
{
public MyAssemblyException() :
base ()
{
}
public MyAssemblyException( string s) :
base (s)
{
}
 
Search WWH ::




Custom Search