Methods to handle exceptions in a web project using C#

前端 未结 5 971
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 01:36

What is the best way to handle exceptions occurring in catch statements. Currently we are writing the exception message to response object\'s write method. But I want a solution

5条回答
  •  我寻月下人不归
    2021-02-09 01:49

    For the web project and to guard against any exceptions getting pushed down to the browser, you could enable Health Monitoring and also the use of Custom Error Pages. If you are expecting the possibility of an exception inside the catch statement, simply nest another try catch in there so that it falls over graciously.

    In the global.asax also you can subscribe to the Application_Error event, which will be called for an unhandled exception

    Andrew

    Health Monitoring in ASP.NET : http://www.4guysfromrolla.com/articles/031407-1.aspx

提交回复
热议问题