// wake up the loop. We can ignore these messages.
return;
}
-
- // The function should never throw an exception, because we have no
- // way of knowing what sort of error handling to perform.
- //
- // If it does throw, log a message and abort the program.
- try {
- msg();
- } catch (const std::exception& ex) {
- LOG(ERROR) << "runInEventBaseThread() function threw a "
- << typeid(ex).name() << " exception: " << ex.what();
- abort();
- } catch (...) {
- LOG(ERROR) << "runInEventBaseThread() function threw an exception";
- abort();
- }
+ msg();
}
};
ASSERT_LE(c1.getCount(), 11);
}
+TEST(EventBaseTest, messageAvailableException) {
+ auto deadManWalking = [] {
+ EventBase eventBase;
+ std::thread t([&] {
+ // Call this from another thread to force use of NotificationQueue in
+ // runInEventBaseThread
+ eventBase.runInEventBaseThread(
+ []() { throw std::runtime_error("boom"); });
+ });
+ t.join();
+ eventBase.loopForever();
+ };
+ EXPECT_DEATH(deadManWalking(), ".*");
+}
+
TEST(EventBaseTest, TryRunningAfterTerminate) {
EventBase eventBase;
CountedLoopCallback c1(&eventBase, 1,