Asio exception handling
Hi, Consider the example where an io_service objects is used as scheduler, with tasks handed to io_service::post(). According to the manual [1], exceptions should propagate to the caller of io_service::run. However, this does not seem to be the case with the attached example. Essentially, I am doing the following: while (true) { try { io_service.post(task(&work)); io_service.post(task(&work)); io_service.post(task(&work)); io_service.run(); break; } catch (...) { // Never reached! std::cout << "catching exception" << std::endl; } } I attached a minimal example that demonstrates this issue. Any help would be appreciated. Matthias [1] http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/io_servic... -- Matthias Vallentin vallentin@icsi.berkeley.edu http://www.icir.org/matthias
Consider the example where an io_service objects is used as scheduler, with tasks handed to io_service::post(). According to the manual [1], exceptions should propagate to the caller of io_service::run. However, this does not seem to be the case with the attached example.
ASIO has nothing to do with it. You wrap your function with packaged_task, and it doesn't propagate exceptions. Modify your example as follows to see what happens: struct task { //.... void operator()() { (*pt_)(); boost::unique_future<void> fi=pt_->get_future(); assert(fi.has_exception()); } //... };
On Sun, Feb 14, 2010 at 05:59:32PM +0200, Igor R wrote:
ASIO has nothing to do with it. You wrap your function with packaged_task, and it doesn't propagate exceptions.
Of course, thanks for the reminder. Matthias -- Matthias Vallentin vallentin@icsi.berkeley.edu http://www.icir.org/matthias
participants (2)
-
Igor R
-
Matthias Vallentin