C#异常信息获取

try
{
    int i = 0;
    int a = 10 / i;
}
catch (Exception ex)
{
    /**
     * 1.异常消息
     * 2.异常模块名称
     * 3.异常方法名称
     * 4.异常行号
     */
    String str = "";
    str += ex.Message + "\n";//异常消息
    str += ex.StackTrace + "\n";//提示出错位置,不会定位到方法内部去
    str += ex.ToString() + "\n";//将方法内部和外部所有出错的位置提示出来
    MessageBox.Show(str);
} 

记录下来主要是为了记录系统异常日志所使用

posted @ 2016-04-26 15:22  段江涛IT  阅读(3544)  评论(0编辑  收藏  举报
页脚HTML代码