I have a method that could return NullPointer
and in this case, a default 0.0 value must be used.
I'm wondering if there are differences between
double a=0.0;
try{
a=somemethod();
catch(NullPointerException exc){
}
return a;
and
double a;
try{
a=somemethod();
catch(NullPointerException exc){
a=0.0;
}
return a;
If yes what is the best approach?
NOTE:
somemethod()
is just a sample, really It is a method of a library that I cannot edit or fix to avoid NullPointer
at the source so I must use catch block.