A Warning When Using -fno-exceptions

As an embedded C++ developer, I typically write programs with exceptions disabled. My typical method for accomplishing this is by using the -fno-exceptions compiler flag. Unfortunately, I never realized a very important detail: even if I compile with -fno-exceptions, the C++ libraries I'm using have not been compiled with -fno-exceptions.

In order to be truly safe under this condition, I would need to avoid any standard library functions which might throw an exception, because they still will throw even if I cannot catch.

While some compilers, such as Keil, will correctly link a C++ library variant with exceptions disabled, this behavior is not guaranteed. If you are unsure whether a different library is being linked, I recommend compiling the C++ runtime with exceptions disabled. In this case, throw calls will be replaced with abort, which should be defined appropriately for your system.

Further Reading