CustomException is an application exception that supports remoting. : Custom Exception « Language Basics « C# / CSharp Tutorial






using System;
using System.Reflection;
using System.Runtime.Serialization;

[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyCultureAttribute("")]


[Serializable]
public class CustomException : Exception {

    public CustomException(): base("custom exception", null) {
        prop_Time = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString();
    }

    protected CustomException(SerializationInfo info,StreamingContext context)
        : base(info, context) {
        prop_Time = info.GetString("Time");
    }

    public override void GetObjectData(SerializationInfo info, StreamingContext context) {
        info.AddValue("Time", prop_Time, typeof(string));
        base.GetObjectData(info, context);
    }

    protected string prop_Time = null;
    public string Time {
        get {
            return prop_Time;
        }
    }
}








1.24.Custom Exception
1.24.1.User-Defined Exception Classes
1.24.2.Use a custom Exception
1.24.3.Derived exceptions must appear before base class exceptions.
1.24.4.A custom exception with HelpLink and Source
1.24.5.Extends Exception
1.24.6.Create your own exception class based on Exception
1.24.7.CustomException is an application exception that supports remoting.