Download GNAT Pro User's Guide

Transcript
Chapter 2: Using GNAT Pro Features Relevant to High-Integrity
10.
11.
12.
13.
14.
15.
16.
17.
18.
null;
end;
begin
C := C - 1;
|
>>> warning: pragma Restrictions
(No_Exception_Propagation) in effect,
"Constraint_Error" may call
Last_Chance_Handler
end;
begin
raise Program_Error;
|
>>> warning: pragma Restrictions
(No_Exception_Propagation) in effect,
Last_Chance_Handler will be called
on exception
19.
end;
20. end p;
These warnings may be turned off globally using the switch -gnatw.X, or by
using pragma Warnings (Off) locally.
As shown by the warnings above, if an exception handler If any other exception is raised, it is treated as unhandled, and causes the last chance handler to
be entered.
In a High-Integrity program, you can forbid exception handling entirely, but
still allow the raising of exceptions by using:
pragma Restrictions (No_Exception_Handlers);
No handlers are permitted in a program if this restriction is specified, so exceptions can never be handled in the usual Ada way. If run time checking is
enabled, then it is possible for the predefined exceptions Constraint_Error,
Program_Error, or Storage_Error to be raised at run time.
When such an exception is raised, a call is made to the routine designated
by the symbol __gnat_last_chance_handler. This routine has distinct parameters for the ZFP and Ravenscar SFP profiles vs. the Cert and Ravenscar Cert
profiles, as detailed in the profile-specific sections.
If your program may raise Constraint_Error, Program_Error, or Storage_
Error, then the application must include an appropriate “last chance handler”
to deal with the fatal errors represented by these exception occurrences. This
handler can be written in C or in Ada using the profile-specific parameters. All
9