自定义异常示例:namespace WinForm
{
    public class CustomException : Exception
    {
        #region Fields        private int line;        #endregion        #region Constructors        public CustomException(int line, string message, Exception innerException)
            : base(message, innerException)
        {
            this.line = line;
        }        public CustomException(int line, string message)
            : this(line, message, null)
        {
        }        public CustomException(int line)
            : this(line, string.Empty)
        {
        }        #endregion        #region Properties        public int Line
        {
            get
            {
                return line;
            }
        }        #endregion
    }
}抛出自定义异常:    throw new CustomException(3, "; expected");捕捉自定义异常:            catch (CustomException ex)
            {
                string msg = string.Format("位置: {0},错误描述: {1}", ex.Line, ex.Message);
                MessageBox.Show(msg);
            }