- 抽离Try/Catch代码块。他们搞乱了代码结构,把错误的处理与正常流程混为一谈。
最好把try和catch代码块的主题部分抽离出来,另外形成函数。
public void delete(Page page){
try{
deletePageAndAllReference(page);
}catch(Eception e){
logError(e);
}
}
private void deletePageAndAllReference(Page page) throws Exception{
deletePage(page);
....
....
}
有了这样美妙的区隔,代码就更易于理解和修改了。 ····························································································