My app is swallowing OOM exceptions and the only s...
# coroutines
d
My app is swallowing OOM exceptions and the only suspect I have is
supervisorScope
. Is it swallowing
CancellationException, VirtualMachineError, ThreadDeath, LinkageError, InterruptedException
and other "fatal" errors? If so, how to ensure it doesn't. I may have confused myself wrt
CoroutineExceptionHandler
Can it rethrow the exception? My reading of it is that it's just a non-control hook.
d
CoroutineExceptionHandler
handles the exceptions it's provided. With it, you can avoid exceptions crashing your application. If you want your application (on Android) to crash, simply don't use any
CoroutineExceptionHandler
.
d
well, i don't want it to crash for a lot of exceptions, but i don't want it to merrily go along on "fatal" exceptions. I've added a rethrow on fatal error to it. I just hope it doesn't catch itself into an infinite loop
d
It won't do that, no. If you rethrow the exception from the handler, it will behave as if there were no handlers.
d
perfect. the doc string says
You cannot recover from the exception in the
CoroutineExceptionHandler
. The coroutine had already completed with the corresponding exception when the handler is called. Normally, the handler is used to log the exception, show some kind of error message, terminate, and/or restart the application.
but gives no hint as to how to terminate or restart. I guess I overinterpreted "cannot recover" as saying it was outside the control flow.
d
"Cannot recover" here means that if your coroutine failed, nothing you write in
CoroutineExceptionHandler
can make it continue executing, it will stop in any case.