我开始玩 boost::threads,但我有点被这个问题困扰:
我不明白为什么这个程序会在抛出异常后立即崩溃,因为我试图在线程中捕获它。我认为只要处理发生在与 throwing 相同的线程中,就有可能处理异常?
#include <boost/thread.hpp>
#include <exception>
using namespace std;
void doWork();
void thrower();
int main( int argc, char** argv ){
boost::thread worker(doWork);
worker.join();
return 0;
}
void doWork(){
try{
thrower();
}
catch( const exception &e ){
//handle exception
}
}
void thrower(){
// program terminates as soon as the exception is thrown
throw exception();
}
附加信息:
*使用 MinGW32
*Boost v.1.44
*动态链接多线程调试 dll 线程库的版本