Skip to content

Commit

Permalink
改个地方,能 抓到 异常。看来只有这种地方的异常能抓到
Browse files Browse the repository at this point in the history
  • Loading branch information
microcai committed Oct 5, 2024
1 parent 7601e31 commit ee4a1b0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/test5/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ ucoro::awaitable<int> coro_compute_int(int value)
auto ret = co_await executor_awaitable<int>([value](auto handle) {
main_ioc.post([value, handle = std::move(handle)]() mutable {
std::this_thread::sleep_for(std::chrono::seconds(0));
throw std::bad_alloc{};
std::cout << value << " value\n";

// 这里调用后,重新进入协程框架.
handle(value * 100);
});

// 这里 return 后,就出协程框架了.
});


// 放这里能抓到
throw std::bad_alloc{};

co_return (value + ret);
}

Expand Down

0 comments on commit ee4a1b0

Please sign in to comment.