is traditionally thrown with failed blocking IO requests, the linter produces this warning. Because it is simply a warning, you are welcome to ignore assuming you know the risks of such a call, which I believe that in this case, there aren’t any real risks of blocking the current thread as
doStuff
should be executed in a different coroutine on a different thread (at least in theory a different thread)
Ok so the IDE assumes doStuff is a blocking function because it can throw
IOException
and shows the warning. So if I wrap it with try catch it should go away?
Sergio C.
10/20/2021, 9:59 PM
try catch didn't work in my code
e
ephemient
10/20/2021, 9:59 PM
won't work, it's still something "blocking" inside your suspend function whether it's wrapped or not
s
Sergio C.
10/20/2021, 10:04 PM
I'm concerned I'm doing something wrong, or blocking the coroutine.
Copy code
val json = String(e.response()?.errorBody()?.source()?.readByteArray() ?: byteArrayOf(), StandardCharsets.UTF_8)
readByteArray here shows the same warning. yep it throws IOException
This line is the catching of HttpException from suspend retrofit call. I need to get the response body even if I don't get a 200 OK.