https://kotlinlang.org logo
Title
a

Adriano Celentano

09/11/2019, 8:39 AM
someone else exeperienced exceptions thrown by retrofit which are not caught by the try catch surounding the call ?
j

Joaquim Ley

09/11/2019, 9:14 AM
Which exception are you referring to and what’s on you catch clause?
a

Adriano Celentano

09/11/2019, 11:45 AM
GlobalScope.launch(handler) {
            try {
                someSuspendingFunctionWhichAlsoCallsRetrofit()
            } catch (it: Throwable) {
                logError(it)
            }
        }
--> E/AndroidRuntime: FATAL EXCEPTION: main
catch and exceptionHandler are not called just get this Androidruntime exception (which should be a unknownhostexception, but is appreaently cut by android since some newer versions )
in the end i maed my retrofit client blocking an wrapped it myself in coroutines
👍 1
g

gildor

09/11/2019, 2:35 PM
Could you please show full stacktrace
a

Adriano Celentano

09/11/2019, 3:33 PM
unfortunately thats all Android gives me
E/AndroidRuntime: FATAL EXCEPTION: main
i assume it it an UnkownHostException, it seems like retrofit throws the exception two times and one time it is not catched
p

Pablichjenkov

09/11/2019, 6:11 PM
I did experience that behavior with okhttp async api. Some Network errors were not caught internally by the library. I ended up wrapping the sync api in a try/catch on my own Observable using RXjava. Then later I migrated that to coroutines Flow. I end up with an extension method in Call<T> class named asFlow that internally wraps the sync call in a try/catch. It then emits a result or throws.
j

jw

09/11/2019, 8:52 PM
Use 2.6.1
🙌 1
a

Adriano Celentano

09/12/2019, 7:36 AM
@jw thx, i already read your post before and updated but it didnt help me unfortunately