Comments (5)
I am not really commenting on the proposal here (I'm definitely not against it), but I strongly disagree with the main example provided, and thus the listed upside 2.
You should most likely never catch IllegalStateException
(I have yet to see a case where this is beneficial, and this example is not one of them). If you need to catch ISE because you know of the specific situation where it is thrown (like the checkNotNull
for your token), I would 100% vote for using a dedicated exception type there and catch this one specifically. It is both more readable and more correct, because the intent is to catch this specific instance of ISE, not any ISE, so we can use the type system to express this.
That said, I'm also quite surprised that CancellationException
is a subtype of IllegalStateException
(I did not know that, and I have quite a bit of experience with coroutines).
from kotlinx.coroutines.
As far as I see, CancellationException is defined as:
public actual typealias CancellationException = java.util.concurrent.CancellationException
So perhaps the plan was to deal with Java's java.util.concurrent.CancellationException as if it was CancellationException thrown from coroutines ?
from kotlinx.coroutines.
Note that this is a change not just in the library, but in the language as well. The exception is defined in the standard library https://github.com/JetBrains/kotlin/blob/0938b46726b9c6938df309098316ce741815bb55/libraries/stdlib/src/kotlin/coroutines/cancellation/CancellationExceptionH.kt#L13, and the compiler notifies the Apple targets that it is fine for suspend
functions to throw this CancellationException
.
from kotlinx.coroutines.
Maybe this issue warrants a structured-concurrency label as well?
from kotlinx.coroutines.
@LouisCAD structured-concurrency is for a specific (backwards-compatible) project that aims to solve all (most) of the labeled issues with a dedicated API layer. This one, unfortunately, is much more profound
from kotlinx.coroutines.
Related Issues (20)
- Kotlin collect flow wont work in a react-native bridge HOT 1
- Remove @ExperimentalCoroutinesApi from CancellableContinuation.resume(...) HOT 2
- kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation HOT 12
- Flow multiplexing HOT 1
- Play Services artifact Gradle Module Metadata doesn't advertise the sources jar's existence HOT 2
- How to use Flows in an imperative mode? HOT 3
- Provide an API to invoke a callback on job cancellation
- Even After bumping kotlinx coroutine test dependency to 1.8.0 giving an UncaughtExceptionsBeforeTest. HOT 4
- ThreadLocal.asContextElement may not be cleaned up when used with Dispatchers.Main.immediate HOT 8
- `kotlinx.coroutines.debug`'s `module-info.java` is incorrect preventing any project using JPMS to use debug probes
- BlockHound false positive in kotlin.jvm.internal.Reflection.renderLambdaToString HOT 3
- java.lang.NullPointerException: Cannot invoke "kotlinx.coroutines.flow.Flow.collect when bumping up coroutines 1.6.4 to 1.8.1 HOT 2
- Improve the API reference HOT 3
- Coroutine on EventLoop dispatcher fails to yield to a task which is resuming after a delay HOT 5
- TestScope swallows an exception thrown from `launch` outside `runTest` HOT 4
- Exceptions being swallowed during tests / UncaughtExceptionsBeforeTest HOT 5
- Flow collection silently hangs when dispatcher throws an exception
- Suggestion for a potential new Flow's `timeout` extension HOT 2
- Mutex is unlocked on cancellation HOT 2
- Crash on GraalVM at `1.9.0-RC` HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlinx.coroutines.