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

  • 相关阅读:
    jsp开发环境搭建(windows64位)
    python环境和工具
    判断单链表是否有环及寻找环的入口
    Eclipse实用操作
    img标签在div里上下居中
    继承小结
    创建对象
    方法链、作用域链和原型链(三)——原型链
    python截取字符串
    在vscode上运行python
  • 原文地址:https://www.cnblogs.com/softidea/p/3421916.html
Copyright © 2011-2022 走看看