```private suspend fun logRemotelyBestEffort(info:...
# coroutines
u
Copy code
private 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?
you can catch it, but it is possible that it is an exception thrown by something other than your timeout (e.g. perhaps propagated from a call made within the logging implementation)
it may be easier to use
withTimeoutOrNull()
u
oh the orNull variant, thanks!