Exception异常常见属性

废话少说,直接上代码:

 try
            {
                int n = Convert.ToInt32("@");
            }
            catch(Exception ex)
            {
                Console.WriteLine("Message:"+ex.Message+ ",Source:" + ex.Source+ ",StackTrace:" + ex.StackTrace+ ",TargetSite:" + ex.TargetSite);
            }

异常如下:

Message:输入字符串的格式不正确。,

Source:mscorlib,

StackTrace: 在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)

在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
在 System.Convert.ToInt32(String value)
在 ConsoleApp1.Program.Main(String[] args) 位置 F:代码存放AspConsoleApp1ConsoleApp1Program.cs:行号 15,

TargetSite:Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)

原文地址:https://www.cnblogs.com/shuai7boy/p/9758913.html