3 ms·
This is a good example,and the error returned by the Java DNS library is obviously wrong. However, I don't think that simply returning the file IO exception wou
by tsimionescu 7y ago
This is a good example,and the error returned by the Java DNS library is obviously wrong. However, I don't think that simply returning the file IO exception would have been the right solution. The best solution would have been for the DNS resolution error to have carried the FileIO error as a Cause. That way, code that could recover from a DNS resolution error could handle the DNS resolution problem, and code that couldn't would still log the actual root cause.
The Java networking libraries seem to be particularly poorly written for DNS error handling. I encountered an error where I was opening a socket to connect to a hostname, with an explicit timeout of a few seconds (it was an external service, but the application was supposed to work offline as well). To my surprise, the call would block for a few minutes on a customer system. It turned out that the call was first resolving the hostname, and that the timeout value I supplied was not applied to the DNS resolution, which was using a system-wide default timeout.
One other point about your example: I think that one thing missing from all language runtimes that I have seen is a proper logging mechanism that is truly available language-wide. Of course there is always stdout/stderr, but these are usually far too limited and it is nkt considered good form to log to them from libraries. Even if you did, you would obviously not respect the application logging format in regards to stuff like time format, timezone etc. In contrast, a standardized configurable logging mechanism would help so much with 3rd party library debugging.