Paulius Ruminas
08/27/2019, 6:58 PMCancellationException
? Cancelling the job is a normal operation that is not considered as an error. Code snippet:
job = scope.launch {
try {
// proccess the action
} catch (e: CancellationException) {
throw e
} catch (e: Throwable) {
// log the error
}
}
reline
08/27/2019, 7:02 PMjob = scope.launch {
try {
// proccess the action
} catch (e: Throwable) {
coroutineContext.ensureActive()
// log the error
}
}
Marc Knaup
08/27/2019, 7:06 PMMarc Knaup
08/27/2019, 7:08 PMif (e is CancellationException) throw e
Or make it an extension function:
e.rethrowCancellation()
Paulius Ruminas
08/27/2019, 7:08 PMCancellationException
when catching all errors. I see a lot of Job was cancelled
in our kibana logs which are just job cancellations not real errors so I was wondering is there a different approach.reline
08/27/2019, 7:09 PMensureActive()
the coroutine is no longer active then yes, you’re correct. Is that possible?Marc Knaup
08/27/2019, 7:09 PMCancellationException
would just be a Throwable
and catch-all is just e: Exception
.
Catching Throwable
is still evil, isn’t it? 😄Paulius Ruminas
08/27/2019, 7:10 PMMarc Knaup
08/27/2019, 7:12 PMError
and that means something is REALLY wrong (like OutOfMemoryError
).
I’d rather restart the server then and fix asap than trying to keep a potentially unstable JVM alive.Marc Knaup
08/27/2019, 7:13 PMCancellationException
instead of logging it 😂Marc Knaup
08/27/2019, 7:13 PM.logIfNotCancel
🙂Marc Knaup
08/27/2019, 7:16 PMlaunch
code into try … catch (Throwable)
Marc Knaup
08/27/2019, 7:17 PMscope.launchWithExceptionLogging { … }
Marc Knaup
08/27/2019, 7:19 PMMarc Knaup
08/27/2019, 7:20 PMgildor
08/28/2019, 4:14 AMMarc Knaup
08/28/2019, 2:41 PMgildor
08/28/2019, 3:04 PM