ursus
05/24/2021, 3:18 AMprivate suspend fun logRemotelyBestEffort(info: LogMessage) {
try {
withTimeout(1000) {
pushApiClient.log(info)
}
} catch (ex: Exception) {
when (ex) {
is TimeoutCancellationException -> Unit
is CancellationException -> throw ex
else -> ...
}
}
}
I hear I'm not supposed to catch CancellationException or I'll break coroutines. But then TimeoutCancellationException extends CancellationException
Is that fine to catch? Or should withContext be outside the try catch?ephemient
05/24/2021, 5:46 AMephemient
05/24/2021, 5:46 AMephemient
05/24/2021, 5:46 AMwithTimeoutOrNull()
ursus
05/24/2021, 6:19 AM