zoukankan      html  css  js  c++  java
  • 异常处理 以此警示后人

    异常类Exception 

    记录成文本日志 

    有些人喜欢记录ex.Message 

    这样记录一般只有一行中文的错误提示 

    结果查原因半天查询不不到 

    直接序列化Exception 也会出现一定的问题会报循环引用问题

    我们一般向下面这样处理

    /// <summary>
            /// 创建异常消息
            /// </summary>
            /// <param name="ex">异常信息</param>
            /// <param name="remark">备注</param>
            /// <returns>结果</returns>
            private static StringBuilder CreateErrorMessage(System.Exception ex, string remark)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("************************Exception Start********************************");
                string newLine = Environment.NewLine;
                System.Exception innerException = ex.InnerException;
                stringBuilder.AppendFormat("Exception Date:{0}{1}", DateTime.Now, Environment.NewLine);
                if (innerException != null)
                {
                    stringBuilder.AppendFormat("Inner Exception Type:{0}{1}", innerException.GetType(), newLine);
                    stringBuilder.AppendFormat("Inner Exception Message:{0}{1}", innerException.Message, newLine);
                    stringBuilder.AppendFormat("Inner Exception Source:{0}{1}", innerException.Source, newLine);
                    stringBuilder.AppendFormat("Inner Exception StackTrace:{0}{1}", innerException.StackTrace, newLine);
                }
                stringBuilder.AppendFormat("Exception Type:{0}{1}", ex.GetType(), newLine);
                stringBuilder.AppendFormat("Exception Message:{0}{1}", ex.Message, newLine);
                stringBuilder.AppendFormat("Exception Source:{0}{1}", ex.Source, newLine);
                stringBuilder.AppendFormat("Exception StackTrace:{0}{1}", ex.StackTrace, newLine);
                stringBuilder.AppendFormat("Exception Remark:{0}{1}", remark, newLine);
                stringBuilder.Append("************************Exception End************************************");
                stringBuilder.Append(newLine);
                return stringBuilder;
            }
  • 相关阅读:
    SDNU 1123.Encoding
    SDNU 1120.ISBN号码
    SDNU 1119.Intelligent IME(水题)
    SDNU 1115.谁拿了最多奖学金(水题)
    解决Docker运行命令时提示"Got permission denied while trying to connect to the Docker daemon socket"类情况
    jupyter notebook修改默认浏览器
    CentOS切换用户命令su or su+username
    图像内插,双线性插值等
    python求最大公约数和最小公倍数
    Python split()方法
  • 原文地址:https://www.cnblogs.com/liuxiaoji/p/9177645.html
Copyright © 2011-2022 走看看