https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

spierce7

08/26/2021, 5:00 PM
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

louiscad

08/26/2021, 5:11 PM
Re-throwing like that is fine. I personally take this approach.
s

spierce7

08/26/2021, 7:07 PM
Would anything bad happen if I didn’t rethrow?
l

louiscad

08/26/2021, 7:10 PM
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.
5 Views