How do exceptions simplify my function return type and parameter types?
When you use return codes, you often need two or more distinct return values: one to indicate that the function succeeded and to give the computed result, and another to propagate the error information back to the caller. If there are, say, 5 ways the function could fail, you could need as many as 6 different return values: the “successful computation” return value, and a possibly different package of bits for each of the 5 error cases. Let’s simplify it down to two cases: • “I succeeded and the result is xxx.” • “I failed and the error information is yyy.” Let’s work a simple example: we would like to create a Number class that supports the four arithmetic operations: add, subtract, multiply and divide.