我有以下代码:
TestClass test=new TestClass();
test.setSomething1(0); //could, but probably won't throw Exception
test.setSomething2(0); //could, but probably won't throw Exception
Run Code Online (Sandbox Code Playgroud)
我想执行:test.setSomething2(0);即使test.setSomething(0)(它上面的行)抛出异常.有没有办法做到这一点以外:
try{
test.setSomething1(0);
}catch(Exception e){
//ignore
}
try{
test.setSomething2(0);
}catch(Exception e){
//ignore
}
Run Code Online (Sandbox Code Playgroud)
我有很多test.setSomething连续,所有这些都可以抛出异常.如果他们这样做,我只想跳过那一行并转到下一行.
为了澄清,我不在乎它是否抛出异常,我无法编辑抛出此异常的代码的源代码.
这是我不关心例外的情况(请不要使用普遍量化的陈述,例如"你永远不应忽视异常").我正在设置一些Object的值.当我向用户呈现值时,无论如何我都会进行空检查,因此如果执行任何代码行并不重要.