Joffrey
05/18/2020, 7:31 AMtry {
// some suspending operations to connect to web socket
} catch(e: Exception) {
throw WebSocketConnectionFailedException("meaningful high-level msg", e)
}
But when coroutine machinery like withTimeout
is used around this code, it doesn’t behave as expected (we’re expecting a TimeoutCancellationException
but get another one).
To solve this problem, I add an extra catch to rethrow CancellationException
as-is, but it doesn’t feel right…
try {
// so some operations to connect to web socket
} catch(e: CancellationException) {
throw e // no wrapping here
} catch(e: Exception) {
throw WebSocketConnectionFailedException("meaningful high-level msg", e)
}
Is there a better / built-in way to do this?marstran
05/18/2020, 8:07 AMException
, and pass everything else through.