- Show students that they should put the exception inside the loop if they want the program to abort, and put it outside the loop if they want the program to continue.
- Check out our example Java code that demonstrates error checking with three different methods that sum numbers in a list.
- The first way is to forgo error checking altogether.
- The second way is to have code continue upon encountering an error.
- The third way is to have code halt upon encountering an error.
- To help students solidify this concept, give them an assignment in which they must do the following:
- Write any exception that works (using try/catch syntax).
- Put this exception in a larger context and then show how we have exception propagation up to the caller.
- Use an exception within a loop!