``` runBlocking { try { va...
# announcements
l
Copy code
runBlocking {
        try {
            val listener = aSocket(ActorSelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)).tcp().bind(InetSocketAddress(12345))
            val socket = listener.accept()
            println("client connected")
            socket.openReadChannel().readInt()
        }
        catch (ex: Throwable) {
            println("client disconnected")
        }
    }
when i connect to this and then disconnect it throws a `CancellationException`which is caused by an
IOException
. More specifically, it is thrown in
readInt()
because it's trying to read data from a closed stream. I know i can and should only catch that specific exception at that specific line, but for the example code i wrapped the entire thing in catch Throwable to make double sure it catches everything. But even though I catch it and the catch block is executed just fine the exception is still thrown into the console. why is that?
s
Maybe something inside the implementations of
listener
and/or
socket
are logging the exception before throwing it?
l
no, it is logged after its thrown
"client disconnected" appears first
sockets are from ktor btw
s
What happens if you put a
try
around the
runBlocking
and
catch
any Throwables it may throw?