Why are exception errors built in different environments?

I have this code snippet for handling special exceptions

private static final String CONNECTION_REFUSED_EXCEPTION = "java.net.ConnectException: Connection refused: connect";
...
} catch (org.apache.axis.AxisFault af) {

            if (af.getFaultString().equals(CONNECTION_REFUSED_EXCEPTION))
            {
               // Do something
            }
}

This works fine in a Windows development environment

However, when I deploy to a unix machine for testing, the failure line is different as shown below (note: there is no connection at the end)

  • Windows Failure String: java.net.ConnectException: Connection refused: connect
  • Unix Failure Line: java.net.ConnectException: Connection refused

Why is this so?

For the record, I believe the following would be better suited for matching the failure string:

...
if(af.getCause() instanceof java.net.ConnectException)
...
+3
source share
4 answers

" " . , . (Throwable.getMessage()).

, . instanceof, .

Edit:

, ( getCause() null), , , (, java.net.ConnectException). , , getCause() null .

+4

:

  • .
  • , . , , Java.
  • Java , ..
  • , Java, . ( , , .)

, , . , , , , ( ), , .

+3

JVM Windows Unix? (, Sun), .

0

The original error line (maybe?) Coming from the apache axis library. Double check if you use the same version of the library on both machines (lines may vary depending on versions). Another reason is "localization." Some fault lines are localized and may differ on machines with different language settings. I checked it too.

0
source

Source: https://habr.com/ru/post/1773220/


All Articles