[問題] C++ Exception interactions with Threads
抱歉 上面那一篇文章我沒有查清楚原因就發問
問題是這樣,下面的 test() 無法捕捉到 hello 丟出的例外
我用 debug 模式下 trace 了一下堆疊的狀態
hello 和 main 運行在不同的 threads (也就是不同的堆疊)
我想問的是如果 test 必須處理 hello 所丟出的例外
有甚麼方式能夠做到呢?
謝謝
#include <iostream>
#include <boost/thread/thread.hpp>
void hello()
{
std::cout <<
"Hello world, I''m a thread!"
<< std::endl;
throw "exception";
}
void test()
{
try{
boost::thread thrd(&hello);
thrd.join();
}catch(...){
std::cout << "exception";
}
}
int main()
{
test();
}
ps http://www.gamedev.net/reference/articles/article953.asp
網路上的文章,有提到 exception 跟 thread XD
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.96.34
→
12/16 22:36, , 1F
12/16 22:36, 1F
→
12/16 22:37, , 2F
12/16 22:37, 2F
推
12/17 09:32, , 3F
12/17 09:32, 3F
→
12/17 14:16, , 4F
12/17 14:16, 4F
→
12/17 14:19, , 5F
12/17 14:19, 5F
→
12/17 14:20, , 6F
12/17 14:20, 6F
→
12/17 14:22, , 7F
12/17 14:22, 7F
→
12/17 14:23, , 8F
12/17 14:23, 8F
推
12/17 19:30, , 9F
12/17 19:30, 9F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章