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
Dmitry Khalanskiy [JB]
10/18/2024, 2:02 PM
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
Don Mitchell
10/18/2024, 2:03 PM
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
Dmitry Khalanskiy [JB]
10/18/2024, 2:05 PM
It won't do that, no. If you rethrow the exception from the handler, it will behave as if there were no handlers.
d
Don Mitchell
10/18/2024, 2:07 PM
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
Dmitry Khalanskiy [JB]
10/18/2024, 2:10 PM
"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.