.NET: How to convert Exception to string?

前端 未结 10 629
隐瞒了意图╮
隐瞒了意图╮ 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:08

    If you call ToString on Exception object, you get the class name appended by the message, followed by inner exception and then the stack trace.

    className + message + InnerException + stackTrace
    

    Given that, InnerException and StackTrace are only added if they are not null. Also, the fields you have mentioned in the screenshot are not part of standard Exception class. Yes, exception does offer a public property called "Data", that contain additional user-defined information about the exception.

提交回复
热议问题