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

  • 相关阅读:
    常见英语缩写Abbreviations
    Outlook2016邮件如何设置靠右的预览窗格/Reading Pane?
    Power BI Server的SharePoint Credentials设置,OAuth2 + None
    Power BI 怎么定时同步自己电脑上的数据,并在Power BI server上定时刷新报表?
    Black Unique 全球购骑士卡 吃喝玩乐全有折扣
    怎么导出、同步OneNote上面的笔记到另一台电脑的解决方案
    Spring Cloud Gateway 网关内置API
    Spring Cloud Gateway 过滤器
    Spring Cloud Gateway 路由谓词工厂
    Spring Cloud Gateway 路由定位器
  • 原文地址:https://www.cnblogs.com/softidea/p/3421916.html
Copyright © 2011-2022 走看看