General Exception Handling Strategy for .NET

后端 未结 11 1485
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 08:51

I’m used to having try/catch blocks in every method. The reason for this is so that I can catch every exception at the point of infraction and log it. I understand, from my

11条回答
  •  温柔的废话
    2020-12-15 09:30

    How does one avoid try/catch in every method, yet still log the error at the point at which it occurred?

    It depends on the hosting env. Asp.Net, WinForms, and WPF all have different ways of capturing unhandled exceptions. But once the global handler is passes an exception instance you can determine the point of throw from the exception, as each exception includes a stacktrace.

提交回复
热议问题