You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Catch C++ exceptions (and other types of exceptions) and forward to logcat #562
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.
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.
Activity
ljbade commentedon Nov 16, 2014
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.
ljbade commentedon Nov 16, 2014
OK got all the JNI functions wrapped.
ljbade commentedon Nov 16, 2014
Done in 2aed807
ljbade commentedon Nov 18, 2014
Encountered crash where we are not catching C++ exceptions.
Need to add.
ljbade commentedon Nov 22, 2014
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?
jfirebaugh commentedon Nov 24, 2014
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.
ljbade commentedon Nov 30, 2014
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.
ljbade commentedon Jan 13, 2015
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
addr2linetool.ljbade commentedon Jan 13, 2015
Done.