Whats the best practice when you have a try catch ...
# coroutines
s
Whats the best practice when you have a try catch block that catches
Throwable
inside a coroutine with CancellationException? I’m not relying on
CancellationException
anywhere in code, and I don’t want it to show up in my logs. Should I just be watching for it and then re-throwing it, or is it acceptable to just eat it and not throw it?
Copy code
} catch (e: CancellationException) {
                throw e
            } catch (t: Throwable) {
                logger.w(RuntimeException("Error validating file", t))
                count++
            }
l
Re-throwing like that is fine. I personally take this approach.
s
Would anything bad happen if I didn’t rethrow?
l
Depends on the code surrounding it. In my case, I had infinite loops, and preventing cancellation from completing froze the app because of the loop that failed and was retried fast.