What are the best practises for exception handling...
# coroutines
a
What are the best practises for exception handling inside of an actors? Any unhandled exception gets propagated to the actors' channel, so the actor will not react to further incoming messages. I understand the more the codebase is using actors, the more this allows to model the entire architecture in a different way and handle the recovery logic at a higher level. But sometimes I might be using actors just in a specific area of the codebase to save a state without having to deal with thread confinement myself (eg, like the example of the counter in the kotlin docs), and in such a case maybe (?) i want to protect the actor from failures with some explicit try catch inside the actor itself. Is this a bad idea? Are there any preferred patterns to dead with this? Any suggestion?
e
Starting with new version unhandled errors in
actor
are now propagated to
CoroutineExceptionHandler
and you can customize its behavior.
e
No. Deferred is a future that fully incapsulates its result (including a potential error). You are always supposed to handle (
await
) all deferred’s that you have, so exception is never going to be lost.
đź‘Ť 1