Is there a better way for catching specific Exception with a message then doing this:

```
try{
   methodThatWillProbablyThrowASocketException();
} catch(SocketException e){
   if(e.getMessage().contains("reset")){
      // the connection was reset
      // will ignore
   } else{
      throw e;
   }
}

```

For example the `HttpStatusException` gives me the Method `getStatusCode()` where i can easily compare if the error status was 404 or 502 and the can decide what to do:

```
try{
   methodThatWillProbablyThrowAHTTPException();
} catch(HttpStatusException e){
   if(e.getStatusCode() == 404){
      // not found, will not continue
   } 
   if else(e.getStatusCode() == 502){
      // server errror, try again
   } else{
      throw e;
   }
}

```

Most other Exceptions dont give me prober Methods, just the Message.

So my question is, is it the right way to do it? With String compares? Or is there a better way?