Catch all cpp exceptions from app

Catch all cpp exceptions from app
0.0 0


Where I can place global catch(…) in android cocos2dx project in order to able to collect all the cpp exceptions in my project?

I have a cocos2dx project for presentation display for android.
When my cpp code crashed I want to be able to catch all the exceptions and at least shutdown gracefuly.
(And at max - collect the logs and save them \ send to server).

I know that cpp exceptions can’t go to JAVA on android. So I think solution can be, at first, to be able to catch all cpp exceptions. At windows I have main.cpp when I can place global catch(...) like that:

but at android its different.

Maybe there is some good solution for such, I suppose, often problem?


There are prebuilt frameworks you can use:
Crashlytics -

And a discussion of these and others .


Thanks for replay,
can crashlitics collect NDK errors? Can it works without android Activity?

…And whats even more important for me, can crashlitics send logs to my own server, rather then crashlitics servers?


I’d suggest putting in some research. Nobody can tell you if a product meets your needs, except you.


Ok then,
first - crashliticas can’t do send logs to another server, and its works highly rely on android Activity, so my original question is still remains active.
The questions is what is the simple way of implementing exception intercepting above cocos app?

I wonder, maybe catch exceptions somewhere at Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp around cocos2d::Director::getInstance()->mainLoop(); call ? Or in that case I will miss something?


did you find an answer to this? I’m looking doing similar too.


Unless you’re trying to get rid of Crashlytics so that you don’t have to include their SDK or rely on them I would recommend just using their SDK and integration.

First off I’d try to catch errors where they occur. Possibly compile w/exceptions and try/catch around code you know may fail. Check for error values or errno after suspect calls.

You’ll prob want to catch Java’s unhandled exceptions and NDK’s signals (SIGSEGV, et al) for all crashes within your or cocos2d-x’s C/C++ code.

LMGTFY (prob repeat some links, but did a quick research session)

You should be able to set up two different handlers for global exceptions. You’ll need to serialize/parse the stack traces and figure out how to send the data you want back to your server.

While stackoverflow isn’t always the best advice here’s one with a handful of options:

Hook into Crashlytics
If you want to try and use Crashlytics, but also send to your server (this will only catch Java-side errors, most of which won’t be very useful to you): .

Android Java Exceptions .

Android NDK (C++) Exceptions . . . .
Which links to source example:


Thanks for the links! I will try it soon and report how it will go (together with integrate android sturdo build - debug (cocos 15 where are you?))).
Frankly, I doubt that crashlitics can provide good stacktrace for cpp crash (more than just SIGFAULT somewhere but It would be great if it can).


Google has acquired Crashlytics to make it part of their Firebase exception reporting. It is really hard to get C++ stack traces and Crashlytics is very good at unwinding the stack.