Hello, I've run into a problem throwing an excepti...
# coroutines
o
Hello, I've run into a problem throwing an exception from inside
runBlocking
block. I have a test in which I mock an external service integration throwing an exception. Via
runBlocking
I call the suspending function, which in turn creates a new CoroutineScope using
CoroutineScope(coroutineContext + <http://Dispatchers.IO|Dispatchers.IO>)
and creates many deferred calls using
async
to the mocked external service, then uses
awaitAll()
to get their results. Surrounding this code is a try/catch block, which handles the exception. I've stepped in and all of this is working fine. The problem is when the suspending function returns, the surrounding block declares it exited exceptionally and throws an exception from the runBlocking call. Since I'm handling the exception, what's the right way to prevent the context from picking up the exception?
Thinking about it, seems like what I want to do is when creating the scope is to not use the current context, is that right?
s
try/catch handle + supervisorscope
you're missing the latter
if you swallow/handle the exception in the supervisorScope then it won't bubble up