-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Catch C++ exceptions (and other types of exceptions) and forward to logcat #562
Comments
Hmm have encountered this problem: xroche/coffeecatch#13 Will use the patch for the moment. Also need to watch xroche/coffeecatch#11 as we use multiple threads. |
OK got all the JNI functions wrapped. |
Done in 2aed807 |
Encountered crash where we are not catching C++ exceptions. Need to add. |
Hmm, I don't think we can much about catching exceptions thrown in other libuv threads without really hacking up the code with #ifdefs for Android. If we try to catch the errors then log and rethrow, we lose the stack trace pointing to the line of code that threw. So I suggest for every C++ exception we throw (or subclass from std::exception) we also log an error to Log. But what do we do about places where stdlib throws an exception? Can we hook all exception throwing? Have seen some refs to __cxa_throw in http://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c @jfirebaugh thoughts? |
At a language and runtime level, C++ exceptions don't really ever have a stack trace. Particular operating systems print a stack trace if the program crashes -- which is in essence what happens when an exception goes uncaught -- but there's no language level or portable way to get a stack trace from an exception. That's just par for the course in C++ development, and so I'm not concerned about "losing" a stack trace by catching an exception and translating it to another error signaling mechanism. |
I tried various ways to print a log error when there is an unhandled exception but it always killed the program before it the log was flushed. I have decided to just let exceptions crash, but will make sure all places we throw an exception, an error is logged first to aid debugging. |
I think I am going to remove coffeecatch. it just doesn't seem to work very well and has yet to help me with a crash. The default Android crash log seems good enough when combined with the |
Done. |
Currently if a C++, CPU exception, or bad memory read occurs in the C++ code the Android log (logcat), only outputs a generic SIGxxx message saying our process was terminated.
This is useless for tracing errors in the C++ code. We want a full stack trace instead that highlights the offending line of code, similar to what happens if an exception occurs in the Java code.
Some reading on how to handle this problem:
The text was updated successfully, but these errors were encountered: