File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Is there any Exception Handling priority method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is there any Exception Handling priority method?" Watch "Is there any Exception Handling priority method?" New topic
Author

Is there any Exception Handling priority method?

David Scholl
Greenhorn

Joined: Jul 09, 2010
Posts: 21
I use two general error-pages. But always second page (/errorPage.faces) works. What do you recommend to use for this?
Haina Minawa
Ranch Hand

Joined: Oct 13, 2011
Posts: 119
Javid Sch wrote:I use two general error-pages. But always second page (/errorPage.faces) works. What do you recommend to use for this?


The super exception class always takes over precedence, so you should not catch the java.lang.Exception. Instead, you should catch specific exceptions.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

most specific match win! probably your exception would be other than javax.faces.application.ViewExpiredException, i.e, some SubClassOfJava.Lang.Eception
Ankush Kaundal
Ranch Hand

Joined: May 12, 2011
Posts: 36

It may be because the exception that is thrown is not javax.faces.application.ViewExpiredException rather it is some subclass of Exception so always second handler comes into picture.
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

Haina Minawa wrote:The super exception class always takes over precedence...

Seetharaman Venkatasamy wrote:most specific match win!


I've seen both these statements, but they can't both be correct! I decided since I couldn't find a good clear answer googling, I'd try for myself. I created two Exception classes - a GenericException and a SpecificException as a subclass of the former. I then added this to my web.xml:


When I build a servlet that throws a SpecificException, the SpecificExceptionHandler.jsp is served with Tomcat 6.0. Same with Tomcat 5.5. If I reverse the entries in my web.xml, same thing - the more specific class is matched.

If that's any indicator of the spec (I hope it is), it looks like it favors the most specific exception class.


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Most likely is that your ViewExpiredException is being wrapped by another exception of some description - ServletException? Thus it doesn't match on the first pass.

Basically it makes a pass through the list of handled error pages.
If it doesn't find a match, then it looks at the exception cause, and tries that for a match.

Because you have a matcher for "Exception" it stops there without looking at the cause.
If you didn't have the declaration there with java.lang.Exception, it would probably work as you were wanting it to.

I would suggest replacing



with


and see if that works for you.

David Scholl
Greenhorn

Joined: Jul 09, 2010
Posts: 21
Stefan, yes it works. thanks!
 
 
subject: Is there any Exception Handling priority method?
 
Similar Threads
Error Page redirection is not working with JSF2.0
Redirect internal server error to custom JSP
<error-page> tag in web.xml is not working
Handle all error codes other than one
doubt in error page for DD