My binary crashes with the following lines
I DEBUG : pid: 1190, tid: 1367, name: Binder_1 >>> /system/bin/fingerprint_proxy <<<
I DEBUG : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
I DEBUG : Abort message: 'terminating with uncaught exception of type std::__1::ios_base::failure: ios_base::clear: unspecified iostream_category error'
Code that caused the exception looks like this
try {
std::ofstream out;
out.exceptions( std::ofstream::failbit | std::ofstream::badbit );
out.open("bad_path");
} catch(std::ios_base::failure &e) {
// skipped
}
For some reason exception wasn't caught so i added more catch blocks
try {
std::ofstream out;
out.exceptions( std::ofstream::failbit | std::ofstream::badbit );
out.open("bad_path");
} catch(std::ios_base::failure &e) {
// skipped
} catch(std::__1::ios_base::failure &e) {
// skipped
} catch(std::exception &e) {
// skipped
} catch(...) {
// caught
}
This time only the last catch block caught the exception, and to be sure it's not an inheritance issue i added.
try {
throw std::ios_base::failure("miau");
} catch(std::exception &e) {
// caught
}
My Android.mk looks like this
include $(CLEAR_VARS)
LOCAL_CFLAGS := -Wall
LOCAL_CPPFLAGS := -Wno-write-strings -Wall -std=c++11 -fexceptions
LOCAL_SRC_FILES := test.cpp
LOCAL_MODULE := test_app
LOCAL_MODULE_TAGS := optional
include external/libcxx/libcxx.mk
include $(BUILD_EXECUTABLE)
I get std:: namespace and exception implementation from shared library libc++.so which included by "include external/libcxx/libcxx.mk". So i compiled libc++.so staticlly.
include $(CLEAR_VARS)
LOCAL_CFLAGS := -Wall
LOCAL_CPPFLAGS := -Wno-write-strings -Wall -std=c++11 -fexceptions
LOCAL_SRC_FILES := test.cpp
LOCAL_MODULE := test_app
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libc++
include external/libcxx/libcxx.mk
include $(BUILD_EXECUTABLE)
And it worked!
Exceptions were caught by std::exception clause, although it multiplied binary size by 8, so this is not a solution.
So it seems like exceptions that thrown by shared library are not caught.
Any one has idea why?
A gist for your convenience https://gist.github.com/amfern/2377e9a3cd1ccc0186ea
std::exception
notstd::exceptions
– NathanOliver