Say you want to do this:
double d, x , y;
....
d = x / y;
and you can't say if y == 0 or not.
Should you do this:
if( y == 0){
....
} else {
d = x/y;
}
or
try{
d = x/y;
} catch (ArithmeticException e){
...
}
or when dealing with objectsthat maybe null should you check if it is null first an `if` or `catch` the NullPointerException when you 'use' it?
Which is better and for what reason?
double d, x , y;
....
d = x / y;
and you can't say if y == 0 or not.
Should you do this:
if( y == 0){
....
} else {
d = x/y;
}
or
try{
d = x/y;
} catch (ArithmeticException e){
...
}
or when dealing with objectsthat maybe null should you check if it is null first an `if` or `catch` the NullPointerException when you 'use' it?
Which is better and for what reason?