Exception.Message vs Exception.ToString()

后端 未结 7 879
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 06:44

I have code that is logging Exception.Message. However, I read an article which states that it\'s better to use Exception.ToString(). With the latt

7条回答
  •  独厮守ぢ
    2020-12-04 07:47

    In addition to what's already been said, don't use ToString() on the exception object for displaying to the user. Just the Message property should suffice, or a higher level custom message.

    In terms of logging purposes, definitely use ToString() on the Exception, not just the Message property, as in most scenarios, you will be left scratching your head where specifically this exception occurred, and what the call stack was. The stacktrace would have told you all that.

提交回复
热议问题