Previous | Next | Table of Contents | Index | Program List | Copyright
6.9 Tricks of the Trade: Testing with Exception Handling
Ada's exception handling provides a powerful tool for designing programs whose
behavior is predictable even if its inputs are badly formed or out of range. If
exception handling were not available, it would be the programmer's
responsibility to validate all incoming data--for example, by checking its
range with an IF
statement. Indeed, Ada programs can certainly be
written this way--with no use of exception handling--but the result would not
take advantage of this built-in power.
Even if exception handling is used to advantage, however, the programmer still
has several important responsibilities in this area:
- Analyze your program so that you know the places where exceptions may be
raised, and be sure to place exception handlers in appropriate blocks in your
program. This will ensure that exceptions are not unexpectedly passed back to
the calling program or to the run-time system.
- When you test your program, be sure to test it with badly formed or-out-of
range data so that your exception-handling flow is tested. When you are
finished testing, you should be confident that you know exactly what your
program will do under each set of input conditions. The test data supplied to
Program 6.12 shows an example of how this is done.
In summary, Ada's
exception handling provides a useful way to take account of unusual
circumstances in your program but does not relieve you of the responsibility to
design and test carefully so that your program's behavior will always be
predictable.
Previous | Next | Table of Contents | Index | Program List | Copyright
Copyright © 1996 by Addison-Wesley Publishing Company, Inc.