.NET: How to convert Exception to string?

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

    For displaying some details to user you should use ex.Message. For displaying to developers you will probably need ex.Message and ex.StackTrace.

    There is no 'secret' method, you could consider Message property to be best fit for user friendly message.

    Also be careful that in some case you may have inner exception in exception you catch which would be also useful to log.

提交回复
热议问题