我希望如果有一个java.net.ConnectException
,将调用onFailure
块。但是它没有按预期工作。
你能帮忙吗?
Socket(ip, port).use { socket: Socket ->
val outputStream = socket.getOutputStream()
outputStream.write(valueOn)
outputStream.flush()
state = State.FINISHED
}.runCatching {
state = State.FAILED
}.onFailure {
state = State.FAILED
}