A method is implemented to compute a formula that involves dividing a quantity by a variable y. If y is 0, then an ArithmeticException will be thrown. How should you handle this situation? Here are some alternatives: 1. Ignore the problem and let your method throw an ArithmeticException. 2.Test for y==0 before doing the computation and, if found, print an error message and return 0. 3.Surround the computation with a try/catch block and print an error message in the catch block before returning 0. a. Compare these three alternatives. That means talk about how each is the same as or different than the other two. b. Is there a fourth alternative that is better than these three? If there is, give it along with a justification. If there is not, explain why not.
A method is implemented to compute a formula that involves dividing a quantity
by a variable y. If y is 0, then an ArithmeticException will be thrown.
How should you handle this situation? Here are some alternatives:
1. Ignore the problem and let your method throw an ArithmeticException.
2.Test for y==0 before doing the computation and, if found, print an error message
and return 0.
3.Surround the computation with a try/catch block and print an error message in
the catch block before returning 0.
a. Compare these three alternatives. That means talk about how each is
the same as or different than the other two.
b. Is there a fourth alternative that is better than these three? If there is,
give it along with a justification. If there is not, explain why not.
Step by step
Solved in 2 steps