Commit 6a6ea7ca authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook GitHub Bot

Handle task exceptions in ThreadedExecutor

Summary: Make it consistent with the other executors.

Reviewed By: yfeldblum

Differential Revision: D25926045

fbshipit-source-id: ad2f101fbba918fe2a421e394870bf67c0a044b9
parent 118e9141
......@@ -76,7 +76,14 @@ void ThreadedExecutor::controlWait() {
}
void ThreadedExecutor::work(Func& func) {
try {
func();
} catch (const std::exception& e) {
LOG(ERROR) << "ThreadedExecutor: func threw unhandled " << typeid(e).name()
<< " exception: " << e.what();
} catch (...) {
LOG(ERROR) << "ThreadedExecutor: func threw unhandled non-exception object";
}
auto id = std::this_thread::get_id();
with_unique_lock(finishedm_, [&] { finished_.push_back(id); });
notify();
......
......@@ -16,6 +16,8 @@
#include <folly/executors/ThreadedExecutor.h>
#include <stdexcept>
#include <folly/Conv.h>
#include <folly/futures/Future.h>
#include <folly/gen/Base.h>
......@@ -36,6 +38,11 @@ TEST_F(ThreadedExecutorTest, example) {
EXPECT_EQ("42", ret);
}
TEST_F(ThreadedExecutorTest, exception) {
folly::ThreadedExecutor x;
x.add([] { throw std::runtime_error("This should not crash the program"); });
}
TEST_F(ThreadedExecutorTest, dtor_waits) {
constexpr auto kDelay = std::chrono::milliseconds(100);
auto x = std::make_unique<folly::ThreadedExecutor>();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment