How to catch specific exception in CoroutineExceptionHandler

Viewed 76

I have this CoroutineExceptionHandler:

private val handler: CoroutineExceptionHandler = CoroutineExceptionHandler{ _, exception ->
println(“Exception thrown in one of the children: $exception”)
}

Can I catch specific exceptions (like with try…catch) for example I want to catch java.net.SocketException. Try…catch around the code doesn’t work and I want to alert the user when server closes the connection.

0 Answers
Related