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.
The following switches can be used to control which of the two exception handling methods is used.
gnatmake. This option is rarely used. One case in which it may be advantageous is if you have an application where exception raising is common and the overall performance of the application is improved by favoring exception propagation.
gnatmake. This option can only be used if the zero cost approach is available for the target in use (see below).
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.