First, you should not use eval()
. You have to have a very strong programming domain to use it without problems. And whoever has this domain always finds a better solution.
Division by zero is considered a programming error , it's A simple if
resolves . But in this case neither need since you know that it is 0, you do not have to do this in real code.
Always treating division by 0 as resulting in 0 is a mathematical error, if this were correct the mathematics would do this. And when it makes sense for some other reason than the mathematician is using the number for a function he should not have. Again, programming errors should not be treated as if they were normal, or as exceptions.
When capturing exception, and in good code this rarely occurs, never capture Exception
, this exception it should even be abstract. Perhaps everything that serves to inherit should.
See also: