-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Usually, await
throws a wrong exception for representing a failure of a Deferred
(e.g., of an async
coroutine)
#2086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
await
throws a wrong exception for representing a failure of a Deferred
(e.g., of an async
coroutine)
The ship has sailed with respect to how
Should behave identically to:
|
When the parent scope is such that it automatically fails after a child scope has failed: the two pieces of code you gave as an example cannot have the "same" semantics in principle. Consequently, those pieces of code don't have the "same" semantics at present, despite the fact that the current behavior of When the parent scope is NOT such that it automatically fails after a child scope has failed: the two pieces of code you gave as an example do have the "same" semantics. However, my complaints regarding the current behavior of |
The current behavior:
await
ing the result of aDeferred
(e.g., of anasync
coroutine) throws the original exception in the current coroutine when the current coroutine is failing or is being cancelled as a result of theDeferred
’s failure (e.g., of theasync
coroutine's failure).The proposed behavior:
await
throws aCancellationException
in such cases instead.Here are the reasons why the proposed behavior would be much more appropriate:
the proposed behavior would conform to the paradigm in accordance with which a suspending function throws a
CancellationException
when the current coroutine is failing or is being cancelled.the proposed behavior would be consistent with how
Job.join
andReceiveChannel.receive
work.the proposed behavior would not create the illusion that you can catch the exception generated by a failed
Deferred
(e.g., by a failedasync
coroutine) for the sake of preventing its parent coroutine from failing automatically.Because if you're told that
await
can throw only aCancellationException
under the given circumstances, you understand that once some exception has been thrown, Structured Concurrency has been already applied and you can’t undo it. Thus you know beforehand that the effect of catching an exception is limited, and such a limited effect doesn't contradict common sense.The text was updated successfully, but these errors were encountered: