如何捕获未处理在asp.net应用程序异常?应用程序、异常、未处理、net

2023-09-03 01:09:31 作者:清

在一个.NET的考试我遇到了这个问题。

On a .NET exam I encountered this question.

以下哪一项可以用来捕获未处理的异常在应用程序?

Which of the following can you use to catch unhandled exceptions in an application?

SERVER_ERROR Page_Error事件 的Application_Error Response_Error OnError事件

我知道它的Application_Error,但我想知道的是什么样的人。一些谷歌搜索,我发现的OnError可以用来捕捉任何错误。不过我不知道这件事。你能告诉什么其他的方法来捕获未处理的异常

I know its Application_Error, But what I want to know is what are the others. By some google search I found OnError can be used to catch any errors. Still I am not sure about it. Could you tell what are the other ways to catch unhandled exception

推荐答案

正确的点赶上你未知的错误是的Application_Error

The correct point to catch your unknown errors is the Application_Error.

避免捕捉到的OnError您的网页上,并让系统将其传送到的Application_Error,因为你已经失去了页面上的控制,有什么其他的你可以做,如果不是转移到一些错误页? - 如果您尝试只是重新加载它,你有问题要在一个闭环,可能会导致堆栈溢出

Avoid to capture the OnError on your page, and let the system transfer it to the Application_Error because there you have lost the control on the page, so what other you can do if not transfer it to some error page ? - if you try to just reload it you have the problem to be in a close loop that can cause stack overflow.

这是我的经验,我有问题,当我尝试使用的页面来处理错误的OnError 我用它只有当我不得不释放一些全局存储器,或者类似的东西如果页面上的错误发生。

From my experience I have issue when I try to handle errors using the page OnError and I use it only when I have to free some global memory, or something like that if an error happens on page.

要给出一个总结,试图抓住所有的错误,一个try / catch块,并给出一个消息给你的用户/或只是把这个问题护理,但让未知错误全球捕手记录,并修好它。未知错误的东西,让你失去你的程序的实际控制,而实际上你不知道该怎么办,因为你没有predict - 因此日志,并解决它下一次。

To give a summary, try to catch all your errors inside a try/catch block, and give a message to your user / or just take care of this issues, but let the unknown errors to the global catcher to log it and fix it. The unknown errors is something that make you lose the real control of your program, and actually you do not know what to do because you do not have predict it - so log it and fix it for the next time

有关错误的详细信息: How做我做一个"一般性错误"在我的ASP.NET应用程序页面,以便它处理错误,服务于该页面本身,当触发?

More details about the errors : How do I make a "generic error" page in my ASP.NET application so that it handles errors triggered when serving that page itself?