title: How to set different status code for different type of Exception
body: <p>I am trying to handle Exception in spring boot Application using <code>@ControllerAdvice</code>. I don't want separate methods for each types of exception. I want to handle all types of exception using only one method with main class as <code>@ExceptionHandler(Exception.class)</code></p>
  
  <p>I tried like below it's handling exception properly but problem is that I also want to set different type of status code for different type of exception.</p>
  
  <p>here I am getting <code>500</code> for every type of exception.</p>
  
  <p>can any one tell me how to set different status code for different type of exception?</p>
  
  <pre><code>    @ControllerAdvice
      public class RestExceptionHandler {
  
          @ExceptionHandler(Exception.class)
          public  ResponseEntity&lt;Object&gt;  handleAllExceptionMethod(Exception ex,WebRequest requset) {
  
              ExceptionMessage exceptionMessageObj = new ExceptionMessage();                                   
  
              exceptionMessageObj.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
              exceptionMessageObj.setMessage(ex.getLocalizedMessage());
              exceptionMessageObj.setError(ex.getClass().getCanonicalName());     
              exceptionMessageObj.setPath(((ServletWebRequest) requset).getRequest().getServletPath());
  
              return new ResponseEntity&lt;&gt;(exceptionMessageObj, new HttpHeaders(),HttpStatus.INTERNAL_SERVER_ERROR);       
          }
      }
  </code></pre>