如果满足 IF 语句内的条件,我想执行我的方法callmethod。否则它应该执行 catch block 。但在实现过程中,如果不满足条件,则不会进入catch block 。
try{
if(count==0)
callmethod();
}
catch (Exception e){
System.out.println(e);
}
最佳答案
这是一个很好的方法应用:
try {
if (count == 0) {
callOneMethod();
}
else {
callOtherMethod();
}
catch (Exception e) {
callOtherMethod();
}
这样你就不会出现任何重复的代码,并且在非异常情况下也不会做出带有异常的奇怪事情。
关于java - IF 在 try block 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45440843/