From 8686962cbc97863a0befadf409471252e3a7392e Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 11 Apr 2018 02:27:26 +0200 Subject: [PATCH] catch coroutine error in example --- examples/coroutine1.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/coroutine1.cc b/examples/coroutine1.cc index 4756ff3..35f1ec1 100644 --- a/examples/coroutine1.cc +++ b/examples/coroutine1.cc @@ -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 */