Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Exception C++

Tags:

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?

like image 562
Gidiyo Avatar asked Jul 10 '10 05:07

Gidiyo


People also ask

What is an exception C?

Master C and Embedded C Programming- Learn as you go A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero. Exceptions provide a way to transfer control from one part of a program to another.

Should I use exceptions in C++?

Exceptions are preferred in modern C++ for the following reasons: An exception forces calling code to recognize an error condition and handle it. Unhandled exceptions stop program execution. An exception jumps to the point in the call stack that can handle the error.

How do I get exception messages in C++?

Any code that may throw an exception is placed inside the try block. If an exception is thrown, the catch block is entered, and the program can do the appropriate operation to recover or to alert the user. The code in the finally block is always executed and can do clean up after an exception occurs.

What is __ Cxa_throw?

__cxa_throw. External interface to throw in the C++ support library. Takes three arguments: an exception object, a typeinfo for that object, and a pointer to the destructor to call when we are done with that object.


2 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

like image 145
Tundebabzy Avatar answered Oct 25 '22 17:10

Tundebabzy


You need to build with CrystaX's custom NDK. It has full libstdc++, RTTI and exceptions support. It's generally the best tool for Android development I know.

like image 40
ognian Avatar answered Oct 25 '22 16:10

ognian