Ktorfit icon indicating copy to clipboard operation
Ktorfit copied to clipboard

Catching Fatal Errors

Open ferenczAndras opened this issue 1 year ago • 2 comments

Hi! Is there a way, to set up an error handler, whenever a fatal error happens, the app does not stop, but it gets caught?

For example, when there is no internet connection for the app, I am getting errors like:

FATAL EXCEPTION: main
 Process: com.app.app, PID: 5056
  java.nio.channels.UnresolvedAddressException
 at sun.nio.ch.Net.checkAddress(Net.java:107)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:663)
at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:44)
at io.ktor.network.sockets.ConnectUtilsJvmKt.connect(ConnectUtilsJvm.kt:21) 
at io.ktor.network.sockets.TcpSocketBuilder.connect(TcpSocketBuilder.kt:37)
at io.ktor.client.engine.cio.ConnectionFactory.connect(ConnectionFactory.kt:30)

ferenczAndras avatar Sep 14 '23 14:09 ferenczAndras

Hi, @Foso can you help me point to somewhere, where I can catch the Fatal Errors thrown if there is no internet on the device? What is the best practice for this?

ferenczAndras avatar Oct 02 '23 06:10 ferenczAndras

Hi @ferenczAndras , currently your only way to detect that exception is to wrap the code, where you do the request, inside a try-catch. I started working on improving that situation https://github.com/Foso/Ktorfit/issues/389

Foso avatar Oct 03 '23 13:10 Foso