Let's say I have this if-else statement:
if (isAdd()) {
return addStatement();
} else if (isChange()) {
return chgStatement();
} else if (isDelete()) {
return delStatement();
} else return null;
I want to wrap this in a try-catch statement, but I want to catch the null. How would I do this? I attempted:
try{
if (isAdd()) {
return addStatement();
} else if (isChange()) {
return chgStatement();
} else if (isDelete()) {
return delStatement();
} else return null;
} catch(NullPointerException e){
log.error("null!");
}
return null;
My problem is that I never want to hit the else return null
, but I need to check else if(isDelete())
rather than just else return delStatement();