next up previous
Next: Add a new operator Up: Assignment 8: Process Objects Previous: Readability

Robustness

There are two ways to improve the error-handling of your program: (1) survey the code for operations that can cause errors (like pop), and make sure that they are protected by a precondition (like !stack.empty()), and (2) test a variety of erroneous inputs and try to break it.

1.
Perform both of those steps, in that order. What other operations besides pop can cause errors?

2.
Try out some test cases and see if you both catch the error and produce a useful error message. Your error messages should make sense to the user, not the programmer. For example, ``Not enough arguments for the operator +'' is better than ``Stack empty while translating to postfix.''

Keep in mind that the hypothetical user is just using a calculator; he doesn't know that you are translating to postfix and he has no idea what the stack is.



Allen B. Downey
1999-10-28