(上下文:与应用程序-Jenkins-集成,但并非所有插件都具有良好的设计)
我有这些例外:
public class AbortException extends IOException
在某些情况下,我想捕捉 IOException 但避免捕捉 AbortException
哪一个更正确?
try {
...
} catch (AbortException e) {
throw e //this failure should fail
} catch (IOException e) {
[handle this]
}
或者
try {
...
} catch (IOException e) {
if (e instanceof AbortException)
throw e //this failure should fail
else
[handle this]
}
我不确定在第一种情况下,第二个 catch 块是否会拦截重新抛出的 AbortException