[Ada Information Clearinghouse]
Ada '83 Quality and Style:
Guidelines for Professional Programmers
CHAPTER 7: Portability
Care must be exercised using predefined exceptions since aspects of their
treatment may vary between implementations. Implementation-defined exceptions
must, of course, be avoided. Other guidelines concerning exceptions can be
found in Guidelines
4.3
and
5.8.
Language Ref Manual references:
11.4 Exception Handling,
11 Exceptions
guideline
- Do not depend on the exact locations at which predefined exceptions
are raised.
rationale
The
Ada Language Reference Manual (Department of Defense 1983) states that
among implementations, a predefined exception for the same cause may be raised
from different locations. You will not be able to discriminate between the
exceptions. Further, each of the predefined exceptions is associated with a
variety of conditions. Any exception handler written for a predefined
exception must be prepared to deal with any of these conditions.
Language Ref Manual references:
C Predefined Language Environment
guideline
- Catch
Numeric_Error exceptions with a Numeric_Error | Constraint_Error exception handler.
- Do not use a separate exception handler for
Numeric_Error and
Constraint_Error.
rationale
In cases where
Numeric_Error may be raised, an implementation is allowed to
raise
Constraint_Error instead. In fact, there is no requirement that an
implementation raise the same exception under the same circumstances. It is
not enough to replace the
Numeric_Error exception with a
Constraint_Error.
Either one may be raised; and if
Numeric_Error is raised, it will not be
caught with a simple
Constraint_Error exception handler.
Language Ref Manual references:
11.1 Exception Declarations,
11.2 Exception Handlers,
C Predefined Language Environment
guideline
- Do not raise implementation-defined exceptions.
- Convert implementation defined exceptions within interface packages to
visible user-defined exceptions.
rationale
No exception defined by an implementation can be guaranteed to be portable to
other implementations whether or not they are from the same vendor. Not only
may the names be different, but the range of conditions triggering the
exceptions may be different also.
If you create interface packages for the implementation-specific portions of
your program, those packages can catch or recognize implementation specific
exceptions and convert them into user-defined exceptions that have been
declared in the specification. Do not allow yourself to be forced to find and
change the name of every handler you have written for these exceptions when
the program is ported.
Language Ref Manual references:
11.1 Exception Declarations,
11.2 Exception Handlers,
11.3 Raise Statements
Back to document index