对于我一直在做的一个项目,我们有一些看起来像这样的块:
A类:
try {
callSomeMethod();
}
catch (Exception e) {
throw new SomeCustomExceptionTypeForMetrics("");
}
但是,我的任务是用仅特定“预期”类型的异常替换我们捕获通用异常的所有实例。
问题是 callSomeMethod() 有这样的东西
B类:
try {
if (someCondition...) {
}
else {
//failed
throw new RuntimeException("Timeout while waiting for results")
}
}
catch(InterruptedException e) {
// do some failure stuff here
throw new RuntimeException("Something here");
}
理想情况下,我的团队要求我尽可能少地更改,我无法更改 callSomeMethod() 的签名,但他们也不想只捕获 A 类中的任何 RuntimeException,因为他们不想捕获只是任何类型的 RuntimeException - 只有我们从 B 类中排除的那些。
处理这个问题的最佳方法是什么?