GNAT uses two methods for handling exceptions at run-time. The
longjmp/setjmp method saves the context when entering
a frame with an exception handler. Then when an exception is
raised, the context can be restored immediately, without the
need for tracing stack frames. This method provides very fast
exception propagation, but introduces significant overhead for
the use of exception handlers, even if no exception is raised.
The other approach is called “zero cost” exception handling. With this method, the compiler builds static tables to describe the exception ranges. No dynamic code is required when entering a frame containing an exception handler. When an exception is raised, the tables are used to control a back trace of the subprogram invocation stack to locate the required exception handler. This method has considerably poorer performance for the propagation of exceptions, but there is no overhead for exception handlers if no exception is raised. Note that in this mode and in the context of mixed Ada and C/C++ programming, to propagate an exception through a C/C++ code, the C/C++ code must be compiled with the -funwind-tables GCC's option.
The following switches can be used to control which of the two exception handling methods is used.
longjmp/setjmp approach is available on all targets, but
zero cost approach is only available on selected targets.
To determine whether zero cost exceptions can be used for a
particular target, look at the private part of the file system.ads.
be True to use the zero cost approach. If both of these switches
are set to False, this means that zero cost exception handling
is not yet available for that target. The switch
ZCX_By_Default indicates the default approach. If this
switch is set to True, then the
zero cost approach is
used by default.