Is this locale-proof?

Is there not a better way to determine the type of connection error? I'm guessing not, but it's worth asking.