我有一個C++應用程序,我使用Boost線程來提供併發性。基本示例如下:C++如何在線程產生函數中提升線程拋出的異常
processingThreadGroup->create_thread(boost::bind(process, clientSideSocket, this));
這裏,processingThreadGroup是一個共享指針在升壓線程池和工藝是我需要調用的函數。 clientSideSocket和這是應該傳遞給進程函數的參數。
在處理函數內部,如果檢測到錯誤,我會拋出一個自定義異常。進程函數將數據發送到遠程服務器。所以我的問題是,如何將這個錯誤傳遞給調用堆棧?清理完成後,我想關閉系統。試過以下內容:
try {
processingThreadGroup->create_thread(boost::bind(process, clientSideSocket, this));
} catch (CustomException& exception) {
//code to handle the error
}
但沒有奏效。任何想法如何正確地做到這一點?
謝謝!
它看起來很像'std :: async' _does/do_do_,它使用'future'來處理返回值和異常。 –