Printing an error message and terminating the program is almost as bad, since it gives the program no chance to handle the error. The program that calls the subroutine or uses the class needs to know that the error has occurred. In languages that do not support exceptions, the only alternative is to return some special value or to set the value of some variable to indicate that an error has occurred. However, this only works if the main program bothers to test the return value. And in this case, using -1 as a signal that an error has occurred makes it impossible to allow negative measurements.
Exceptions are a cleaner way for a subroutine to react when it encounters an error.
My modified subroutine throws a ParseError when the user's input is illegal, where ParseError is the subclass of Exception that was defined earlier in this section. Reads the user's input measurement from one line of input. The input line is not empty. No inches have yet been read. If an error is detected during the loop, end the subroutine immediately by throwing a ParseError.