zoukankan      html  css  js  c++  java
  • 了解下C#异常时的输出

    Sample Code:

                try
                {
                    string re = "1.1".Substring(1,4);
                }
                catch (Exception ex)
                {
    
                    logger.ErrorFormat("Exception:
    {0}
     BaseException:
    {1} 
     GetType:
    {2} 
    Message:
    {3}
     StackTrace:
    {4}", ex, ex.GetBaseException(), ex.GetType(), ex.Message, ex.StackTrace);
                }

    Output:

    DayListExtractor.Form1 - Exception:
    System.ArgumentOutOfRangeException: 索引和长度必须引用该字符串内的位置。
    参数名: length
       在 System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
       在 System.String.Substring(Int32 startIndex, Int32 length)
       在 DayListExtractor.Form1.Form1_Load(Object sender, EventArgs e) 位置 G:	estDayListExtractorForm1.cs:行号 63
     BaseException:
    System.ArgumentOutOfRangeException: 索引和长度必须引用该字符串内的位置。
    参数名: length
       在 System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
       在 System.String.Substring(Int32 startIndex, Int32 length)
       在 DayListExtractor.Form1.Form1_Load(Object sender, EventArgs e) 位置 G:	estDayListExtractorForm1.cs:行号 63 
     GetType:
    System.ArgumentOutOfRangeException 
    Message:
    索引和长度必须引用该字符串内的位置。
    参数名: length
     StackTrace:
       在 System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
       在 System.String.Substring(Int32 startIndex, Int32 length)
       在 DayListExtractor.Form1.Form1_Load(Object sender, EventArgs e) 位置 G:	estDayListExtractorForm1.cs:行号 63

     

    总结:

    在需要看情况信息时,打印Exepection ex 实例即可

  • 相关阅读:
    static 静态
    纽扣电池带负载能力差
    JAVA--异常(1)
    【DP专题】——洛谷P1273有线电视网
    我到现在都没有搞明白git233333
    git常见问题之git pull origin master时fatal: refusing to merge unrelated histories
    矩阵内积转化为求矩阵乘积的迹
    矩阵分解系列三:非负矩阵分解及Python实现
    矩阵分解系列三:可对角化矩阵的谱分解
    矩阵分解系列二:正交三角分解(UQ、QR分解)
  • 原文地址:https://www.cnblogs.com/softidea/p/3421916.html
Copyright © 2011-2022 走看看