
On 18/12/2018 02:07, Stian Zeljko Vrba wrote:
1. The above is inside a _/coroutine/_ and invoked as a callback? (my guess: the caller – asio thread – arranges/provides a catch context that the exception propagates into) 2. The above is inside a _/fiber/_ and called by yielding to the fiber scheduler? (my guess: the fiber scheduler does not provide an outer catch context, so the program crashes).
Is this correct?
Yes, both of those are somewhat correct. Though there are some missing links. With coroutines, you're yielding to a specific other coroutine -- if that coroutine throws, then the exception is thrown out of the yield point just as if it were a regular function call. Asio itself doesn't catch any exceptions -- if a handler throws then it will be propagated out and into the method that calls io_context.run() -- if this doesn't have a try-catch block wrapped around it by the user then the thread and the app will be terminated. Fibers aren't allowed to propagate exceptions into the fiber scheduler, since you can't customise the exception handling there -- but if you don't call your fiber code directly but instead wrap it in a packaged_task, this gives you a future and also wraps the code in a try-catch block such that if the code throws an exception it will store the exception into the future (where it can be rethrown at the consuming site) instead of terminating. (Thread-based futures work the same way.)