-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
解决老中医提出的不能 syncAwait 然后捕获异常的问题。测试用例见 test7
- Loading branch information
Showing
4 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
add_executable(test7 test.cpp) | ||
target_link_libraries(test7 ucoro) | ||
|
||
add_test(NAME test7 COMMAND test7) | ||
set_target_properties(test7 PROPERTIES FOLDER "ucoro_tests") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
#include "ucoro/awaitable.hpp" | ||
#include <iostream> | ||
|
||
ucoro::awaitable<int> test() | ||
{ | ||
throw std::runtime_error("test throw"); | ||
co_return 1; | ||
} | ||
|
||
ucoro::awaitable<int> coro_compute() | ||
{ | ||
co_return co_await test(); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
try | ||
{ | ||
std::string str = "hello"; | ||
sync_await(coro_compute(), str); | ||
} | ||
catch (std::exception& e) | ||
{ | ||
std::cerr << "抓到异常" << e.what() << std::endl; | ||
} | ||
|
||
return 0; | ||
} |