当前位置:编程学习 > C#/ASP.NET >>

关于异常的问题

小弟在处理异常时对于自定义的异常还不怎么能把握.希望各位大虾在自定义的异常方面指点一二.最好是有实例说明.
在此谢过. --------------------编程问答-------------------- 自定义异常示例:

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);
            }
--------------------编程问答-------------------- 我好像记得要继承base类
不是很清楚
希望能更加清晰一点
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,