java代码
interface CommandRecovery{
Command recover(Throwable th)
throws Throwable;
}
当某个command失败的时候这个接口会被调用实现这个接口可以有选择地对某一种或者几种错误进行恢复
然后定义具体的错误恢复逻辑
java代码
class RecoveredCommand implements Command{
private final Command c;
private final CommandRecovery c;
public Object execute(CommandContext ctxt){
try{
return cexecute(ctxt);
}
catch(Throwable th){
return crecover(th)execute(ctxt);
}
}
RecoveredCommand (Command c CommandRecovery c){
thisc = c;
thisc = c;
}
}
有trycatch就有tryfinally我们也可以定义一个command让它保证某个关键动作必然运行
[] [] [] [] [] [] [] [] [] [] []