Virus721
Virus721

Reputation: 8335

Android NDK / Exceptions?

I read that only the GNU implementation of the STL supports the C++ exceptions. I'm not sure about what it means exactly.

If I'm not using this implementation, does it mean that :

Upvotes: 1

Views: 4808

Answers (1)

MuertoExcobito
MuertoExcobito

Reputation: 10039

From the Android NDK page:

C++ Exceptions

In all versions of the NDK later than NDKr5, the NDK toolchain allows you to use C++ runtimes that support exception handling. However, to ensure compatibility with earlier releases, it compiles all C++ sources with -fno-exceptions support by default. You can enable C++ exceptions either for your entire app, or for individual modules.

To enable exception-handling support for your entire app, add the following line to your Application.mk file. To enable exception-handling support for individual modules', add the following line to their respective Android.mk files.

So, the NDK can support STL with exceptions, but it is off by default. This page details what happens when you use -fno-exceptions with GNU compilers (and the NDK compiler is gcc based). Since this STL is implemented all in headers, its usage of exceptions depends on whether the code that includes it (eg. your code) is compiled with or without exceptions. If you use exceptions in your code, and compile with -fexceptions, then you can use exceptions as normal in your own code, as well as using exceptions in the STL.

Upvotes: 2

Related Questions