假设我有一个嵌套的自定义异常的集合,可以从控制器或服务中的任何位置抛出。哪种方法更好,为什么?
那么哪种方法是更好的选择? 1.使用try catch块捕获这些异常 2.使用方法接受包含所有业务模块的闭包。
e.g
方法1:
try{
//call the business logic here
}catch(CustomException ex){
// do something
}
方法2.
Controller.action{
// call the business logic here.
}
This method will in turn catch all the exceptions in a try catch
like, this action may look like the following
action(Closure closure){
try{
}
catch(CustomException e)
// do handling
}
这上面是architechture老虎钳更正确,更干净的样子。
大多数哪个问题和问题取决于业务需求而不是技术可行性。这些问题的答案将根据您想要达到的目标来推动。 – kosa 2015-02-24 21:03:16
问题只是在请求的起源处使用try catch还是调用一个服务方法,它只为我执行此操作 – 2015-02-24 21:30:52
还是很好地使用异常...... – cfrick 2015-02-24 21:34:10