Handling of C++ Exceptions #301
ramceb
started this conversation in
Architecture Community
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In general C++ code shall be compiled with
-fexceptions
(i.e., with support for C++ exceptions). The chapter Exceptions - Doing Without of the GNU libstdc++ reference manual explains why:Anyhow in safety-related code, exceptions shall only be used for non-recoverable errors as the stack unwinding itself is not deterministic and not part of the qualification scope of most qualified compilers.
Therefore C++ exceptions shall be avoided.
Anyhow as some libraries e.g. the C++ STL cannot be refactored it can occur that a piece of code which is linked to a safety application throws an exception.
If safety-related code throws an exception, the program shall terminate immediately.
This is necessary to prevent the nondeterministic behavior of exception handling (e.g., unbounded worst-case execution time of destructors during stack unwinding, memory exhaustion during the allocation for the exception to be thrown).
Example implementation:
According to the Itanium C++ ABI Specification, throwing an exception looks like this:
To abort as early as possible
__cxa_allocate_exception()
can be overloaded as it is the first function that is called when throwing an exception.Overload
__cxa_allocate_exception()
to immediately callstd::abort()
:Beta Was this translation helpful? Give feedback.
All reactions