Version 1.1 of ai12s/ai12-0022-1.txt

Unformatted version of ai12s/ai12-0022-1.txt version 1.1
Other versions for file ai12s/ai12-0022-1.txt

!standard 3.2.4(19/3)          12-03-16 AI12-0022-1/01
!class Amendment 12-03-16
!status work item 12-02-24
!status received 12-02-24
!priority High
!difficulty Medium
!subject Changing the exception raised for an assertion
We want to encourage the conversion of comments to predicates/preconditions in existing libraries. However, changing the exception raised may be an unacceptable incompatibility. Some mechanism should be provided to allow specifying the exception to be raised by the failure of an assertion.
There is an optional "exception" clause on predicates and preconditions. This specifies the exception that will be raised on the failure of the check.
Alternative #1: There is an aspect "Raise_Exception" that specifies the exception to raise.
Alternative #2: There a new kind of expression, the raise_expression. This is considered Boolean-valued for resolution purposes; otherwise it has the same syntax as a raise statment (enclosed in parens).
(raise exception_name [with string_expression])
This raises the given exception when evaluated.
Alternative #3: Do nothing. The user can write a function that works like alternative #2:
function Raise_Mode_Error (For_File : File_Type) return Boolean is begin raise Mode_Error with Name (For_File); return False; -- At least one return is required. end Raise_Mode_Error;
Alternatives #2 and #3 would be used in short-circuit or conditional expression:
with Pre => Mode (File) = In_File or else (raise Mode_Error with Name (File));
with Pre => Mode (File) = In_File or else Raise_Mode_Error (File);
** TBD.
Example: Imagine the following routine in a GUI library:
procedure Show_Window (Window : in out Root_Window); -- Shows the window. -- Raises Not_Valid_Error if Window is not valid.
We would like to be able to use a predicate to check the comment. With the "exception" clause we can do this without changing the semantics:
subtype Valid_Root_Window is Root_Window with Dynamic_Predicate => Is_Valid (Valid_Root_Window) exception Not_Valid_Error;
procedure Show_Window (Window : in out Valid_Root_Window); -- Shows the window.
If we didn't have the "exception" clause here, using the predicate would change the exception raised on this failure. That could cause the exception to fall into a different handler than currently, which is likely to not be acceptable.
Similarly, the various Containers packages in Ada could use predicates in this way to make some of the needed checks; but that can only be done if the semantics remains unchanged (raising Program_Error and Constraint_Error, not Assertion_Error). (The !proposal also shows how this could be used in Text_IO and other I/O packages.)
!ACATS test
** TBD.

This AI was split from AI05-0290-1; during meeting #46 there was general
agreement that this is an important issue but the solution looked more
complex than a last-minute fix would allow.


Questions? Ask the ACAA Technical Agent