.NET: How to convert Exception to string?

前端 未结 10 633
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 10:47

When an exception is thrown (while debugging in the IDE), i have the opportunity to view details of the exception:

10条回答
  •  爱一瞬间的悲伤
    2021-01-30 11:13

    Each left-side name is property in the Exception. If you want to display Message field, you can do

    return ex.Message;
    

    Pretty simple. Likewise, the StackTrace can be displayed as below link.

    A complete example of StackTrace: http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx

    and Exception class: http://msdn.microsoft.com/en-us/library/system.exception.aspx

提交回复
热议问题