Exception types derived from exception should be serializable, because only in this way can the exception object be in cross-applicationProgramDomain.
[Serializable]
Public Sealed Class Diskfullexception: exception, iserializable
{
Private String M_diskpath;
Public String Diskpath { Get { Return M_diskpath ;}}
Public Override String Message
{
Get
{
If (M_diskpath = Null ) Return Base . Message;
Stringbuilder msg = New Stringbuilder ( Base . Message );
MSG. appendformat ( " (Diskpath = {0}) {1} " , M_diskpath, environment. newline );
Return MSG. tostring ();
}
}
Public Diskfullexception (): Base (){}
Public Diskfullexception ( String Message ): Base (Message ){}
Public Diskfullexception ( String Message, exception innerexception)
: Base (Message, innerexception)
{}
Public Diskfullexception ( String Message, String Diskpath)
: This (Message)
{
M_diskpath = Diskpath;
}
Public Diskfullexception ( String Message, String Diskpath, exception innerexception)
: This (Message, innerexception)
{
M_diskpath = Diskpath;
}
// Defines a deserialization constructor. Because the class is sealed, the constructor is private;
// Otherwise, the constructor can be protected.
Private Diskfullexception (serializationinfo info, streamingcontext context)
: Base (Info, context)
{
// Deserialization of custom Fields
M_diskpath = Info. getstring ( " Diskpath " );
}
# Region Iserializable Member
// Make sure that the caller obtains the internal status of the object.
[Securitypermission (securityaction. Demand, serializationformatter = True )]
Void Iserializable. getobjectdata (serializationinfo info, streamingcontext context)
{
Base . Getobjectdata (Info, context );
// Serialize custom Fields
Info. addvalue ( " Diskpath " , M_diskpath );
}
# Endregion
}