Global error handling in ASP.NET

前端 未结 2 1513
刺人心
刺人心 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 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.

提交回复
热议问题