简体   繁体   中英

Catching NDK SIGABRT from Java code without access to ndk code

I have a library with ndk code library which is throwing a sigdev on a particular device I have, which kills my app. Is it possible to catch this sigdev and throw a Java exception? The catch must be done without modification to the library which is throwing the exception.

The exception looks like so:

01-26 09:09:38.610 19393-19869/com.foo.bar A/libc: /Volumes/Android/buildbot/src/android/ndk-r12-release/ndk/sources/cxx-stl/llvm-libc++abi/libcxxabi/src/abort_message.cpp:74: void abort_message(const char *, ...): assertion "terminating with uncaught exception of type char const*" failed
01-26 09:09:38.610 19393-19869/com.foo.bar A/libc: Fatal signal 6 (SIGABRT) at 0x00004bc1 (code=-6), thread 19869 (Thread-9201)

There are similar questions asked elsewhere on SO, however it seems that in those cases they control both the NDK and the Java sourc, and use the ndk code to trigger a java exception. In my situation I do not have any control over the ndk code, it is a closed source library, so I must handle it entirely via the Java code, or additional ndk code of my own creation.

You can't catch native exceptions in Java, but you can catch them from C++ and turn them into Java exceptions via a wrapper library. Call your wrapper from Java rather than the original library and let your wrapper library delegate the work but handle exceptions.

This may not work, as catching exceptions across shared library boundaries most likely requires that both libraries are built with RTTI, exceptions, and are using the same STL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM