How should you handle this exceptional situation?

Suppose you are implementing a method to compute a formula that involves dividing a quantity by a variable x. You realize that if x is 0, then an Arithmetic Exception will be thrown. How should you handle this exceptional situation? Here are some alternatives: a. Ignore the problem and let your method throw an Arithmetic Exception. b. Test for x 0 before doing the computation and, if found, print an error message and return 0. c. Surround the computation with a try/catch block and print an error message in the catch block before returning 0. Compare these alternatives. Is there a fourth alternative that is better than these three?


 

. .

get-your-custom-paper

The post How should you handle this exceptional situation? appeared first on Blackboard Masters.

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now