Date: Thu, 13 Apr 2023 22:28:16 +0300
On Thu, 13 Apr 2023 at 22:01, Jason McKesson via Std-Discussion
<std-discussion_at_[hidden]> wrote:
> Considering how difficult it is to answer the basic question in
> coroutines without an explicit `try` block... maybe we should just not
> support these things? Maybe we should just encourage people to use
> `try/catch` blocks if they need to check for scope failure. Yes, it's
> not as visually pleasing, but it solves the problem.
That solution doesn't work, because you can exit scopes with return,
break, and goto as well,
and the whole point of these scope guards is that they are able to run
their cleanup regardless
of how you do the scope exit. And for scope_fail, its purpose is
specifically that you don't
have to catch and rethrow if your function doesn't want to handle
exception. So that's
a complete non-solution.
Warning users that these things don't work in coroutines seems like a
palatable solution to me.
<std-discussion_at_[hidden]> wrote:
> Considering how difficult it is to answer the basic question in
> coroutines without an explicit `try` block... maybe we should just not
> support these things? Maybe we should just encourage people to use
> `try/catch` blocks if they need to check for scope failure. Yes, it's
> not as visually pleasing, but it solves the problem.
That solution doesn't work, because you can exit scopes with return,
break, and goto as well,
and the whole point of these scope guards is that they are able to run
their cleanup regardless
of how you do the scope exit. And for scope_fail, its purpose is
specifically that you don't
have to catch and rethrow if your function doesn't want to handle
exception. So that's
a complete non-solution.
Warning users that these things don't work in coroutines seems like a
palatable solution to me.
Received on 2023-04-13 19:28:30