title: Tomcat: ExceptionHasndler doesn't work for MultiPartException but works correct for IllegalArgumentException
body: <p>I have controller like this:</p>
  
  <pre><code>@PostMapping("/rest_upload1")
  public ResponseEntity upload1(@RequestParam("file") MultipartFile multipartFile) throws IOException {
    throw new IllegalArgumentException();
  }
  </code></pre>
  
  <p>and in configuration I have settings:</p>
  
  <pre><code>spring.http.multipart.max-file-size=100MB
  spring.http.multipart.max-request-size=100MB
  </code></pre>
  
  <p>it means that spring will throw <code>MultipartException</code> in case if file exceeds 100MB.</p>
  
  <p>To handle this exception I wrote handler:</p>
  
  <pre><code>@ControllerAdvice
  public class RestExceptionHandlerAdvice extends ResponseEntityExceptionHandler {
  
      @ExceptionHandler(MultipartException.class)
      @ResponseBody
      public ResponseEntity&lt;ApiError&gt; handleException(MultipartException e) {
           logger.warn("MultipartException:", e);
           ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST,
                  String.valueOf(HttpStatus.BAD_REQUEST),
                  ExceptionUtils.getRootCauseMessage(e),
                  Collections.emptyList());
          return new ResponseEntity&lt;ApiError&gt;(apiError, HttpStatus.BAD_REQUEST);        
      }
  </code></pre>
  
  <p>In case of error this code invokes(i see it in debug)</p>
  
  <p>but in browser I don't see response:</p>
  
  <p><a href="https://i.stack.imgur.com/8VAJB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8VAJB.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/udpPM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/udpPM.jpg" alt="enter image description here"></a></p>
  
  <p>I googled a lot of time and looked loke everuthing ok. And I tried to add handler for IllegalArgumentException:</p>
  
  <pre><code>@ExceptionHandler(IllegalArgumentException.class)
  @ResponseBody
  public ResponseEntity&lt;ApiError&gt; handleException(IllegalArgumentException e) {
  
      ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST,
                  String.valueOf(HttpStatus.BAD_REQUEST),
                  ExceptionUtils.getRootCauseMessage(e),
                  Collections.emptyList());
  
      return new ResponseEntity&lt;ApiError&gt;(apiError, HttpStatus.BAD_REQUEST);            
  }
  </code></pre>
  
  <p>And I upload file less than 100mb. At this case result differs:</p>
  
  <p><a href="https://i.stack.imgur.com/Ao0Ow.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ao0Ow.jpg" alt="enter image description here"></a></p>
  
  <p>But anyway response code is wrong.</p>
  
  <p>What can be wrong?</p>
  
  <h2>P.S.</h2>
  
  <p>I tried:</p>
  
  <pre><code>@ExceptionHandler(MultipartException.class)
  @ResponseStatus(value = HttpStatus.PAYLOAD_TOO_LARGE)
  @ResponseBody
  public String handleException(MultipartException e) {
      return ExceptionUtils.getRootCauseMessage(e);      
  }
  </code></pre>
  
  <p>it looks like the same as here:</p>
  
  <p><a href="https://stackoverflow.com/questions/32867386/how-to-handle-maximum-file-size-exception-in-spring-boot">How to handle maximum file size Exception in Spring Boot?</a></p>
  
  <h2>P.S.2</h2>
  
  <p>I found workaround but it looks like bug in sring:</p>
  
  <p>I added dependencies:</p>
  
  <pre><code>compile "org.apache.commons:commons-io:1.3.2"
  compile "commons-fileupload:commons-fileupload:1.3.3"
  </code></pre>
  
  <p>register beans:</p>
  
  <pre><code>@Bean
  public MultipartResolver multipartResolver() {
      CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
       multipartResolver.setMaxUploadSize(10);
       return multipartResolver;
  }
  </code></pre>
  
  <p>and wrote:</p>
  
  <pre><code>@ControllerAdvice
  public class UploadExceptionHandler {
      @ExceptionHandler(MaxUploadSizeExceededException.class)
      @ResponseStatus(HttpStatus.PAYLOAD_TOO_LARGE)
      @ResponseBody
      public String handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
          return e.getMessage();
      }
  }
  </code></pre>