[Ada Information Clearinghouse]

Ada '83 Quality and Style:

Guidelines for Professional Programmers

Copyright 1989, 1991,1992 Software Productivity Consortium, Inc., Herndon, Virginia.

CHAPTER 7: Portability

7.5 Exceptions

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

In this section...
7.5.1 Predefined Exceptions
7.5.2 Constraint_Error and Numeric_Error
7.5.3 Implementation-Defined Exceptions
Summary of Guidelines from this section


7.5.1 Predefined Exceptions

guideline

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


7.5.2 Constraint_Error and Numeric_Error

guideline

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


7.5.3 Implementation-Defined Exceptions

guideline

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