Commit 0ce40de7 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Fix SemiFuture exception_wrapper use

Summary: exception_wrapper requires the actual exception object to be passed in for any std::exception.

Reviewed By: memorybank

Differential Revision: D8501214

fbshipit-source-id: 034a4c7df9979711dcb3740ca5c4313944f29cb6
parent 69e84f4f
......@@ -93,9 +93,9 @@ TEST(Coro, Sleep) {
EXPECT_TRUE(future.await_ready());
}
coro::Task<void> taskException() {
coro::Task<int> taskException() {
throw std::runtime_error("Test exception");
co_return;
co_return 42;
}
TEST(Coro, Throw) {
......@@ -110,6 +110,18 @@ TEST(Coro, Throw) {
EXPECT_THROW(future.get(), std::runtime_error);
}
TEST(Coro, FutureThrow) {
ManualExecutor executor;
auto future = via(&executor, taskException()).toFuture();
EXPECT_FALSE(future.isReady());
executor.drive();
EXPECT_TRUE(future.isReady());
EXPECT_THROW(future.get(), std::runtime_error);
}
coro::Task<int> taskRecursion(int depth) {
if (depth > 0) {
EXPECT_EQ(depth - 1, co_await taskRecursion(depth - 1));
......
......@@ -846,7 +846,13 @@ class SemiFuture : private futures::detail::FutureBase<T> {
}
void unhandled_exception() {
promise_.setException(exception_wrapper(std::current_exception()));
try {
std::rethrow_exception(std::current_exception());
} catch (std::exception& e) {
promise_.setException(exception_wrapper(std::current_exception(), e));
} catch (...) {
promise_.setException(exception_wrapper(std::current_exception()));
}
}
private:
......
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