diff --git a/include/opendht/thread_pool.h b/include/opendht/thread_pool.h index c8486fd7..1050f101 100644 --- a/include/opendht/thread_pool.h +++ b/include/opendht/thread_pool.h @@ -43,9 +43,15 @@ public: template std::future get(std::function&& cb) { auto ret = std::make_shared>(); - run(std::bind([=](std::function& mcb) mutable { - ret->set_value(mcb()); - }, std::move(cb))); + run([cb = std::move(cb), ret]() mutable { + try { + ret->set_value(cb()); + } catch (...) { + try { + ret->set_exception(std::current_exception()); + } catch(...) {} + } + }); return ret->get_future(); } template