Global error handling in ASP.NET

前端 未结 2 1498
刺人心
刺人心 2021-02-14 20:38

Is there anything wrong with catching errors in an ASP.NET application globally (eg: Global.asax)? I have viewed the question Good error handling practice and it doesn\'t really

相关标签:
2条回答
  • 2021-02-14 20:59

    The global place to handle uncatched Exceptions would be in Global.asax by handling Application_Error. As John pointed out, you should always handle exceptions as close as possible to where they might occur and react appropriately.

    0 讨论(0)
  • 2021-02-14 21:04

    I think so. You should catch exceptions that you might expect on a particular operation as close to it as possible, and behave appropriately, but barring that (or perhaps following it after it does some clean-up and rethrows) a global handler that logs the exception and goes to a general 500 response is a good default behaviour.

    0 讨论(0)
提交回复
热议问题