6

I have done some research around this with conflicting results. To handle this error, some say that I need to implement HandlerExceptionResolver in one of my controllers.

Here are some links for that:

On the other hand, other people are saying that this approach is futile such that the Exception is occuring outside the request handling flow:

I have tried the above solutions but they do not work for me. It appears that the Exception occurs outside of Spring, as expected. I am unable to catch this even with HandlerExceptionResolver.

Community
  • 1
  • 1
Johnathan Au
  • 5,244
  • 18
  • 70
  • 128
  • Are you using Standalone Tomcat distribution or Embedded Tomcat that comes with Spring? – Nitin Arora Jun 23 '15 at 09:29
  • I am using standalone :) – Johnathan Au Jun 23 '15 at 09:31
  • Your question is confusing... What do you want, do you want to have spring handle your exception or spring web flow or ??? – M. Deinum Jun 23 '15 at 09:42
  • Hello, so my issue is that on the web page, I have a file uploading form. The user can then add the over sized file to the form. Tomcat will then stack out. Following the stacktrace, we can see that the exception is being thrown by tomcat. Since tomcat is outside of the application's control, how can we catch the exception and then print a error message on the same page? – Johnathan Au Jun 23 '15 at 09:52
  • Th exception will eventually always be thrown by tomcat as that is your container. As stated your question is confusing, first you mention Spring then out of the blue Spring Web Flow pops up... – M. Deinum Jun 23 '15 at 09:53
  • Ah, my apologies. I did not realise "Web Flow" was a used term in Spring. Computer Science and its many acronyms and reserved words! I was speaking from a more general sense as in the logic flow. – Johnathan Au Jun 23 '15 at 09:56
  • Spring Web Flow is a spring project hence the confusion, you might better rephrase it with the request handling flow instead. – M. Deinum Jun 23 '15 at 10:01
  • Post your configuration (including web.xml) and `HandlerExceptionResolver` and also please state which specific spring version you are using. – M. Deinum Jun 23 '15 at 10:04
  • Are you talking about MultiPartUpload in Spring-MVC?? Cant you just set size by declaring a bean like this : . And you can always list to MultiPartException in your Controller wherever there is file upload. Is this what you are looking for, I dont understand the relevance of tomcat here.. :-( – We are Borg Jun 23 '15 at 12:27
  • 1
    Have a look at this : http://stackoverflow.com/questions/2689989/how-to-handle-maxuploadsizeexceededexception – rajesh Jun 26 '15 at 06:13
  • with the correct bean and `HandlerExceptionResolver` the expection should be handled correctly, see [here](http://stackoverflow.com/a/3230352/3224238) please add your current implementation so we can check what is wrong – Paizo Jun 30 '15 at 07:55

1 Answers1

2

Trying following the approach specified in the link below. Basically, you configure an error page for any un handled exception and then define a handler for the error page. Looks like a decent workaround.

Here is the link http://www.javacodegeeks.com/2013/11/how-to-custom-error-pages-in-tomcat-with-spring-mvc.html

Hope this helps.

Nitin Arora
  • 2,650
  • 1
  • 26
  • 27