Link to home
Start Free TrialLog in
Avatar of Software Programmer
Software Programmer

asked on

what are the exception which will be uncaught in Exception.class and RuntimeException.class

I am working on Spring MVC application. I have configured @ControllerAdvice and caught Exception.class, RuntimeException.class

NullPointerException is being caught under Exception.class

For a particular url hit the server returned 500 error which is not being caught in Exception.class or RuntimeException.class in the global exception handler via @ControllerAdvice

Please let me know what are the exception which will be uncaught in Exception.class and RuntimeException.class
Avatar of mccarl
mccarl
Flag of Australia image

The Javadocs give you all this information...

https://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html

If you look toward the top of the page, you will see that Exception is a subclass of Throwable. Throwable's are also objects that can be caught with a try/catch statement and also thrown by a "throw" statement.

Click on Throwable and then you will see that it actually has 2 subclasses, Exception as you now know but also Error. (Note, Error has a whole heirarchy of subclasses too)

So if you are getting a 500 error (and you are sure that your ControllerAdvice is correctly configured) then perhaps either a Throwable has been thrown, or an Error has been thrown. Now these are reasonably rare things to be thrown though, so you can try catching just Throwable, that should get everything, but I am going to guess that you still may get the 500 error because it isn't that the Throwable is getting through, it is just the the ControllerAdvice isn't actually being used in the particular execution path that is causing your 500 error.
Avatar of Software Programmer
Software Programmer

ASKER

so how to handle it or what would be the solution ? i found out that controller methods which are routed via ajax function calls are getting propagated..However the controller methods which has errors on page load or doesn't comes under ajax calls is not getting handled. It always throws 500 error even though we are sending as BAD REQUEST - 400 in the @controller advice.
There's no real way that I could answer that without having seeing your code and how it all fits together, unfortunately.
ASKER CERTIFIED SOLUTION
Avatar of Software Programmer
Software Programmer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Identified the root cause of the problem.