Hello Everyone, I recently have started using coro...
# coroutines
a
Hello Everyone, I recently have started using coroutine based API calls with Retrofit. While testing on slow(EDGE) network scenarios I am getting a series of
SocketTimeOutExceptions
which is fine. I have all my API calls wrapped in
try.. catch()
block like this
Copy code
try {
viewModelScope.launch {
   apiService.doCall()
   // do other stuff
}
} catch(e: Exception) {}
and in case of flow I am using
.catch()
operator for catching exceptions. My problem is my app randomly crashes with crashstack looking like this.
Copy code
DefaultDispatcher-worker-1
    Process: <appId>, PID: 6524
    <http://java.net|java.net>.SocketTimeoutException: timeout
        at okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException(Http2Stream.java:677)
        at okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.java:685)
        at okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.java:154)
        at okhttp3.internal.http2.Http2ExchangeCodec.readResponseHeaders(Http2ExchangeCodec.java:136)
        at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.java:115)
        at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:94)
This does not happen with all timeouts but happen at random. It seem like there is something is off with coroutine setup/usage/exception handling. Any pointers will help. Thanks!
m
launch
fires off a parallel coroutine. When it throws the error, you have already left the try-catch block.
a
okay thanks!