在三层Asp.Net应用程序异常处理 [英] Exception handling in a three-tier Asp.Net application

查看:90
本文介绍了在三层Asp.Net应用程序异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)据我了解,在三层我们应该实现以下面的方式异常处理Asp.Net应用程序:

1) To my understanding, in a three-tier Asp.Net application we should implement exception handling in the following way:

一个 - 我们应该把的try-catch 块左右code(位于任何三层),从中我们预计的网页正常恢复的块从(当此code产生异常)?

a - we should put try-catch block around block of code ( located in any of the three layers ) from which we expect the page to gracefully recover from ( when this code generates an exception )?

B - 我们不应该把约code(位于无论是在三层),从中我们并不指望页的try-catch 块优雅地歇着。相反,Asp.Net应用程序应该总是设法通过全局异常处理这些未处理的异常(的Application_Error / Page_Error事件)?

b - we shouldn’t put try-catch blocks around code ( located in either of the three layers ) from which we don’t expect the page to gracefully recover from. Instead, Asp.Net application should always manage these unhandled exceptions through global exception handler ( Application_Error/Page_Error )?

2)通过鸭管理未处理异常的主要好处是 plication_Error / Page_Error事件的事实,这样,我们的错误集中在一个地点处理?

2) Is the main benefit of managing unhandled exceptions through Application_Error/Page_Error the fact that this way we centralize error handling in one location?

毕竟,我们可以实现在现场,他们被抛出,即使这些未处理的异常(任何三层抛出),替代了处理(登录,用户重定向到自定义错误页...)相同的结果? !

After all, we could achieve the same results even if these unhandled exceptions (thrown in any of the three layers ) were instead handled ( logged, user redirected to custom error page ... ) at the spot where they were thrown?!

感谢您

推荐答案

1A)是正确的。
1B)有几分正确;你可以让异常从模型/业务层上堆叠到presentation,并显示错误消息。它没有走一路到的Application_Error; Page_Error事件可能是好的,但有些例外可能是(相对)普遍不够,虽然你不能正常恢复,你应该有在某些情况下与它们相关的特定错误消息。

1a) is correct. 1b) is sort of correct; you may let the exception go up the stack from your model/business layers to the presentation, and display an error message. It doesn't have to go all the way to the Application_Error; Page_Error may be good, but some exceptions might be (relatively) common enough that, while you can not gracefully recover, you should have specific error messages related to them in some contexts.

2)基本上;同时也作为一个'所有'例外你未能predict,赶上在更具体的地方。

2) basically; and also as a 'catch all' for exceptions you have not been able to predict and catch in more specific places.

这篇关于在三层Asp.Net应用程序异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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