Is unnecessary error handling recommended in business logic? eg. Null check/Percentage limit check etc
Posted
by
novice_at_work
on Stack Overflow
See other posts from Stack Overflow
or by novice_at_work
Published on 2012-03-27T17:23:59Z
Indexed on
2012/03/27
17:29 UTC
Read the original article
Hit count: 241
java
|error-checking
We usually put unnecessary checks in our business logic to avoid failures.
Eg.
1. public ObjectABC funcABC(){
ObjectABC obj = new ObjectABC;
..........
..........
//its never set to null here.
..........
return obj;
}
ObjectABC o = funABC();
if(o!=null){
//do something
}
Why do we need this null check if we are sure that it will never be null? Is it a good practice or not?
2. int pplReached = funA(..,..,..);
int totalPpl = funB(..,..,..);
funA() just puts a few more restriction over result of funB().
Double percentage = (totalPpl==0||totalPpl<pplReached) ? 0.0 : pplReached/totalPpl;
Do we again need this check?
The questions is: Aren't we swallowing some fundamental issue by putting such checks? Issues which should be shown ideally, are avoided by putting these checks.
What is the recommended way?
© Stack Overflow or respective owner