Show IP address of host in ConnectException
Andrey Turbanov
turbanoff at gmail.com
Fri Jul 21 09:32:54 UTC 2023
Hello.
Recently I was struggling with troubleshooting the Socket connection
to a server via DNS address.
There were multiple IPs assigned to the same DNS address and I wanted
to know exactly which IP java is trying to connect.
Unfortunately default ConnectException doesn't show anything useful in
the exception message
java.net.ConnectException: Connection refused
Even if I enable enhanced exception info
'-Djdk.includeInExceptions=hostInfo' I still only get the DNS address
in the exception message.
java.net.ConnectException: Connection timed out: connect:
myprod-app.global.mycompany.ro:5001
Is it possible to enhance the exception message to show used IP too?
Perhaps guarged with another JVM option.
I think it would be very useful for troubleshooting.
Andrey Turbanov
More information about the net-dev
mailing list