kotlinx.coroutines
kotlinx.coroutines copied to clipboard
Replace TimeoutCancellationException with TimeoutException
trafficstars
In the current version of the library, withTimeout throws TimeoutCancellationException when a timeout was exceeded.
It can lead to very subtle errors, for example:
launch {
val result = withTimeout(...) {
// ... some computation ...
}
// process result
}
TimeoutCancellationException is CancellationException, thus is never reported.
But in the snippet above, it's likely to be a programmatic error. If it is expected to miss the deadline, then withTimeoutOrNull should be used explicitly.
My proposal is deprecation of TimeoutCancellationException and replacement with TimeoutException that is not CancellationException