#include #include #include #include #include #include #include #include #include struct exception : virtual boost::exception { }; void work() { std::cout << "throwing exception" << std::endl; throw boost::enable_current_exception(exception()); } struct task { typedef boost::packaged_task task_type; template task(const F& f) : pt_(new task_type(f)) { } void operator()() { (*pt_)(); } boost::shared_ptr pt_; }; int main() { boost::asio::io_service io_service; 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; } } return 0; }