Detection and Handling
The separation of error detection and handling is fundamental
to writing well designed reusable classes and to using them correctly.
We have a clear separation of "duty". The low level code detects errors,
the higher level code handles the error.
- The class implementer knows when an error occurs because he wrote the
code. He can detect bad parameters, NULL pointers, etc.
- The class user knows how he wants to handle the error. He may want to
- Exit the program
- Output a message and continue the program
- Retry the function that had the error
- Ask the user what to do
- Many other possibilities
- The class implementer can't know which of the above actions
the user wants to take.
- The class user can't know when an error occurred because the user
has no knowledge of the class implemenation.
- Removes error handling code from the code that caused the error
- Makes it possible to catch all kinds of errors,
errors of a certain type, or errors of related types
- Is usually used in situations in which the system can recover.
- Is used when the error will be dealt with by a different part of the
program (i.e., different scope) from that which detected the error
- Can be slow, but we don't care because errors occur very infrequently
- Should not be used as an alternative to proper program control
Last Modified: Monday, 28-Aug-2006 10:16:05 EDT