方法:使用C#来处理异常的Web项目 [英] Methods to handle exceptions in a web project using C#

查看:122
本文介绍了方法:使用C#来处理异常的Web项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是处理catch语句发生的例外的最佳方法。目前,我们正在编写异常消息,以响应对象的write方法。但我想一个解决方案,利用它用户将只得到一般的错误信息出了问题,但我们必须获得有关该错误的详细说明。我想知道的异常在C#处理采用不同的做法。

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 by which the user will get only a general error message that something has gone wrong but we have to get a detailed description about the error. I would like to know the different practices employed for exception handling in C#.

推荐答案

有关Web项目,并防范任何异常越来越下推到浏览器中,你可以使健康监测,并使用自定义错误页。如果您所期望的catch语句内的异常的可能性,只是窝在有另一种尝试捕捉,使其翻倒客客气气。

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.

在Global.asax你也可以订阅Application_Error事件,将被要求未处理的异常

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

安德鲁

健康监控在ASP .NET: http://www.4guysfromrolla.com/articles/031407-1.aspx

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

这篇关于方法:使用C#来处理异常的Web项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆