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 实例即可

  • 相关阅读:
    【python cookbook】【数据结构与算法】4.找到最大或最小的N个元素
    【python cookbook】【数据结构与算法】3.保存最后N个元素
    oracle sql语言模糊查询--通配符like的使用教程
    oracle decode处理被除数为0 的情况
    握草
    oracle if else 判断
    Procdure for wanfo business report
    [转]Oracle 阳历转农历
    阴阳历互相转换方法
    [转]解决crystal report水晶报表在浏览器提示bobj未定义的错误
  • 原文地址:https://www.cnblogs.com/softidea/p/3421916.html
Copyright © 2011-2022 走看看