title: SpringBoot When file upload size limit exceeds getting MultipartException instead of MaxUploadSizeExceededException
body: <p>I have simple SpringBoot app file uploading functionality where max file upload file size is 2 MB.</p>
  
  <p>I have configured <code>multipart.max-file-size=2MB</code> it is working fine.
  But when I try to upload files with larger than 2 MB size I want to handle that error and show the error message.</p>
  
  <p>For that I have my controller implements <code>HandlerExceptionResolver</code> with <code>resolveException()</code> implementation as follows:</p>
  
  <pre><code>public ModelAndView resolveException(HttpServletRequest request,
              HttpServletResponse response, Object handler, Exception exception)
      {        
          Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();
          if (exception instanceof MaxUploadSizeExceededException)
          {
              model.put("msg", exception.getMessage());
          } else
          {
              model.put("msg", "Unexpected error: " + exception.getMessage());
          }
  
          return new ModelAndView("homepage", model);
      }
  </code></pre>
  
  <p>The problem is the Exception Im getting is <strong>MultipartException</strong> instead of <strong>MaxUploadSizeExceededException</strong>.</p>
  
  <p>The stacktrace is:
  <strong>Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field myFile exceeds its maximum permitted size of 2097152 bytes.</strong></p>
  
  <p>In the case of file size exceeds why not I am getting <strong>MaxUploadSizeExceededException</strong>? I am getting its parent Exception <strong>MultipartException</strong> which can be occured for many other reasons in addition to File Size exceeds.</p>
  
  <p>Any thoughts on this?</p>