未从共享库捕获android异常
我的二进制文件在以下几行中崩溃未从共享库捕获android异常,android,c++,exception,fstream,libc++,Android,C++,Exception,Fstream,Libc++,我的二进制文件在以下几行中崩溃 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 ex
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'
由于某些原因,并没有捕获异常,所以我添加了更多的捕获块
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
}
这次只有最后一个catch块捕获了异常,
我补充说,当然这不是继承问题
try {
throw std::ios_base::failure("miau");
} catch(std::exception &e) {
// caught
}
我的Android.mk看起来像这样
try {
std::ofstream out;
out.exceptions( std::ofstream::failbit | std::ofstream::badbit );
out.open("bad_path");
} catch(std::ios_base::failure &e) {
// skipped
}
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)
我从共享库libc++.so获得std::namespace和异常实现,它包含在“includeexternal/libcxx/libcxx.mk”中。
所以我编译了libc++,非常静态
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)
成功了
异常被std::exception子句捕获,
虽然它将二进制大小乘以8,所以这不是一个解决方案
所以,似乎并没有捕获共享库抛出的异常
有人知道为什么吗
为方便起见
将-frtti添加到本地标志解决了问题 由于异常在内部使用RTTI,不指定-frti标志将导致两个表,一个来自libc++,另一个用于我的二进制文件。
注意:由于所有android本机库都是在没有RTTI的情况下编译的,因此不可能将它们包含在-frti编译的二进制/库中。这不是问题中的
std::exceptions
typo,对不起