With Swift or ObjC The error code is included in the caught NSError
let e: NSError = NSError(domain: "unko", code: 931, userInfo: nil)
print(e.code) // <- 931
On the other hand, when I received an exception with HttpURLConnection on Android Java, such a message was displayed. ``failed to connect to /...** (port *****): connect failed: ECONNREFUSED (Connection refused)``` I wondered if this ECONNREFUSED had an error code in Excption, but I searched for it, but getCode like Swift()There is no such thing Eh, getLocalizedMessage()Is it classified from the character string? It is a such a fool I was in trouble with that feeling, but I was a little addicted because no information came out even if I searched #I found it
URL url = new URL("http://unko.com");
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect (); // Exception coming
Log.d("unko", "" + connection.getResponseCode());
Log.d("unko", "" + connection.getContentType());
} catch (Exception e) {
Log.w("unko", "" + ((ErrnoException) e.getCause()).errno);
} finally {
if (connection != null) {
connection.disconnect();
}
}
I got the code in this part
((ErrnoException) e.getCause()).errno // == 111
This 111 seems to come from Linux System Errors There is no doubt that I have also sent a message such as ETIMEDOUT ...
Errors: Linux System Errors http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html
By the way, they had constants defined
OsConstants.ECONNREFUSED
So I got the error code
Yes
#Summary -It's annoying to just take the code -I haven't investigated it properly, so if there is another method, it will be serious. -Java is dung