有时我会这样重新分类异常:
try{
methodA(param1);
}catch(ExceptionType1 ex){
throw new ExceptionType2(ex);
}
我这样做的一个例子是,当 methodA 的参数应该是安全的并且不会引发异常时,ExceptionType1 真正表明了不同的问题(类似于 ExceptionType2)。
这不是从受检异常到未经检查的重新分类。