放在哪里尝试捕捉 [英] Where to put try catch

查看:202
本文介绍了放在哪里尝试捕捉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下情形:  我有3层的应用程序,当此按钮,用户点击该按钮事件处理函数调用BIZ层的方法是做什么用的数据我的按钮事件处理电源,然后传递数据,这些数据将它们发送到后端数据访问层数据库。 现在的问题是在哪里放尝试捕捉?在数据层中,BIZ层中,presentation层或也许把它周围所有的人?怎么重新present异常处理在这种情况下最好的策略是什么?

Consider this scenario: I have 3-layer app, when the user click on the button the button event handler calls a method in biz layer that do whatever with data my button event handler supply and then pass that data to the data Access layer which sends them to the backend database. The question is where to put the try catch? In the data layer, in biz layer, in presentation layer or maybe put it around all of them? What the best strategy to represent exception handling as in this scenario?

推荐答案

我们遵循

不要捕捉异常,如果你不知道该怎么办。

Do not catch exceptions if you do not know what to do with it.

我们从来没有处理任何异常,我们无法处理或默认。它得到冒泡了,我们处理它在应用层。

We never handle any exceptions which we cannot handle or default. It gets bubbled up and we handle it at the application level.

说,如果你能默认值,对于一个businesss对象,那么你就可以处理它在业务层。

Say if you can default a value, for a businesss object, then you can handle it in the business layer.

这篇关于放在哪里尝试捕捉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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