Suppose you are implementing a method to compute a formula


Question: 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?

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Suppose you are implementing a method to compute a formula
Reference No:- TGS02578179

Expected delivery within 24 Hours