当前位置: 技术问答>linux和unix
不同模块间抛出的对象异常为什么捕获不到???
来源: 互联网 发布时间:2015-10-23
本文导语: 现在在LINUX下,有一个可执行文件和一个共享库文件,为什么一个模块中抛出的对象异常,在另外一个模块中捕获不到??? 但是,在同一个模块中是可以捕获不到的,这是为什么原因? (注:抛出的是对象,但如...
现在在LINUX下,有一个可执行文件和一个共享库文件,为什么一个模块中抛出的对象异常,在另外一个模块中捕获不到???
但是,在同一个模块中是可以捕获不到的,这是为什么原因?
(注:抛出的是对象,但如果抛出字符串等其他一些基本类型,在不同模块间也是能捕获到的)
但是,在同一个模块中是可以捕获不到的,这是为什么原因?
(注:抛出的是对象,但如果抛出字符串等其他一些基本类型,在不同模块间也是能捕获到的)
|
首先,你在main里面如何装载共享库的函数?请贴一下你的代码。
我写了一个简单的测试,可以得到异常,不知是否跟你的情况一样:
== a.h ==
class B {
public:
std::string reason() {
return "Except: This is Bn";
}
};
== b.cpp ==
#include
#include "a.h"
int test() {
B b;
throw b;
return 0;
}
============
#g++ -shared -o b.so -ldl b.cpp
#strings b.so|grep test
#_Z4testv
==== a.cpp ====
#include
#include "dlfcn.h"
#include "a.h"
typedef int (*FUNC)(void);
FUNC test;
int main() {
void* dp = dlopen("./b.so", RTLD_LAZY);
if(dp == NULL) {
std::cout
我写了一个简单的测试,可以得到异常,不知是否跟你的情况一样:
== a.h ==
class B {
public:
std::string reason() {
return "Except: This is Bn";
}
};
== b.cpp ==
#include
#include "a.h"
int test() {
B b;
throw b;
return 0;
}
============
#g++ -shared -o b.so -ldl b.cpp
#strings b.so|grep test
#_Z4testv
==== a.cpp ====
#include
#include "dlfcn.h"
#include "a.h"
typedef int (*FUNC)(void);
FUNC test;
int main() {
void* dp = dlopen("./b.so", RTLD_LAZY);
if(dp == NULL) {
std::cout