Enable Exception C++

Viewed 19698

I am trying to make APP native code for Android. The Native code is in cplusplus. Whenever I try to make, the following error appears.

H236Plus.cpp:135: error: exception handling disabled, use -fexceptions to enable

How do I use -fexceptions to enable exception handling, and where do i use it?

8 Answers

It depends on what runtime you are using. If you are not using system runtime and are building with ndk-build, you add any of these to your Android.mk file:

  • LOCAL_CPP_FEATURES += exceptions (Recommended)
  • LOCAL_CPPFLAGS += -fexceptions

Also, you can add the following line to your Application.mk file:

  • APP_CPPFLAGS += -fexceptions

There's more information in docs/CPLUSPLUS-SUPPORT.html in your NDK folder

Just a note for anyone who has started with one of the NDK examples.

They tend to set -fno-exceptions in their CMakeLists.txt, you need to remove it:

set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -Wall -Werror -fno-exceptions -frtti") 

You might want to check whether you want -Werror while you're at it.

Related