Is there any reason to throw a DivideByZeroException?
Posted
by Atomiton
on Stack Overflow
See other posts from Stack Overflow
or by Atomiton
Published on 2010-04-08T15:49:28Z
Indexed on
2010/04/08
15:53 UTC
Read the original article
Hit count: 330
Are there any cases when it's a good idea to throw
errors that can be avoided?
I'm thinking specifically of the DivideByZeroException
and NullReferenceException
For example:
double numerator = 10;
double denominator = getDenominatorFromUser();
if( denominator == 0 ){
throw new DivideByZeroException("You can't divide by Zero!");
}
Are there any reasons for throwing an error like this?
NOTE: I'm not talking about catching these errors, but specifically in knowing if there are ever good reasons for throwing them.
© Stack Overflow or respective owner