• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there any Exception Handling priority method?

 
David Scholl
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stefan Evans
Bartender
Pie
Posts: 1669
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan, yes it works. thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic