I have seen some mistake about Exception used. For example, In UI-Layer which have to call 2-3 service. my co-worker always try-catch for each service call. That is not right.
private void uiAction(){
try {
// Call abcService
} catch (Exception ex){}
try {
// Call defService
} catch (Exception ex){}
}
What's the result?
This code will have a hidden bug about data-flow and it's hard to find.
It should be...
private void uiAction(){
try {
// Call abcService
// Call defService
} catch (Exception ex){
// Display an error to user.
alert(ex)
}
}
Just a simple pattern. You will meet a zero-defect soon. Don't hide any exception.
Anyway, There are 2 kind of Exception, One is Programmatic, Another one is Data-Flow Exception. So you should know how to handle for exception as well.
ไม่มีความคิดเห็น:
แสดงความคิดเห็น