does instanceof work for subclassed exceptions?
问题 java.net.ConnectException extends java.net.SocketException If I do the following, will it cater for both exceptions? ie if I catch a "parent" exception using instanceof , does that include any subclassed exceptions? catch (Exception e) { if (e instanceof java.net.SocketException) { System.out.println("You've caught a SocketException, OR a ConnectException"); } } (and for the record, yes I know catching plain Exceptions is bad, just using it for this example ;) ) 回答1: Exceptions are regular