catch coroutine error in example

master
Daniel Kolesa 2018-04-11 02:27:26 +02:00
parent b0e8b3fbd0
commit 8686962cbc
1 changed files with 8 additions and 3 deletions

View File

@ -42,7 +42,13 @@ int main() {
int val = 5;
for (int i: range(steps)) {
writeln(" calling into coroutine...");
auto v = f(val);
int v;
try {
v = f(val);
} catch (coroutine_error const &e) {
writefln(" coroutine failed: %s", e.what());
return 0;
}
writefln(" called into coroutine which yielded: %s", v);
writefln(" call loop iteration %s done", i + 1);
writefln(" coroutine dead: %s", !f);
@ -290,6 +296,5 @@ starting main...
call loop iteration 6 done
coroutine dead: true
calling into coroutine...
terminating with uncaught exception of type ostd::coroutine_error: dead coroutine
zsh: abort ./coro
coroutine failed: dead coroutine
*/