Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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

Closed

Description

@ljbade

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:

Activity

  1. added
    Android
    on Nov 7, 2014
  2. added this to the Android merge milestone on Nov 13, 2014
  3. ljbade commented on Nov 16, 2014

    @ljbade
    ContributorAuthor

    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.

  4. ljbade commented on Nov 16, 2014

    @ljbade
    ContributorAuthor

    OK got all the JNI functions wrapped.

  5. ljbade commented on Nov 16, 2014

    @ljbade
    ContributorAuthor

    Done in 2aed807

  6. ljbade commented on Nov 18, 2014

    @ljbade
    ContributorAuthor

    Encountered crash where we are not catching C++ exceptions.

    Need to add.

  7. reopened this on Nov 18, 2014
  8. ljbade commented on Nov 22, 2014

    @ljbade
    ContributorAuthor

    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?

  9. jfirebaugh commented on Nov 24, 2014

    @jfirebaugh
    Contributor

    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.

  10. ljbade commented on Nov 30, 2014

    @ljbade
    ContributorAuthor

    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.

  11. reopened this on Jan 13, 2015
  12. ljbade commented on Jan 13, 2015

    @ljbade
    ContributorAuthor

    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 addr2line tool.

  13. ljbade commented on Jan 13, 2015

    @ljbade
    ContributorAuthor

    Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Android

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions