• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

error-page

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone, I'm new here and have a question on error handling in servlet, hope you can help me.
My environment are winme, tomcat4.01, j2ee 1.3
see the following code fragement:
in servlet ...
//1 throw new UnavailableException ("unava", 2);
//2 throw new ServletException ();
//3 throw new RuntimeException();
throw new FileNotFoundException();
in web.xml ...
<error-page>
<exception-type>javax.servlet.UnavailableException</exception-type>
<location>/errorpage/unavailable.html</location>
</error-page>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/errorpage/servlet.html</location>
</error-page>
<error-page>
<exception-type>java.io.FileNotFoundException</exception-type>
<location>/errorpage/io.html</location>
</error-page>
<error-page>
<exception-type>java.lang.RuntimeException</exception-type>
<location>/errorpage/runtime.html</location>
</error-page>
these codes compile. But only line 2 and 3 in servlet code work(the respective error page is displayed). For line 1, tomcat default error page is shown. For line 4, the only content shown are those output by servlet before exception thrown point.
From the previous posts in this forum, someone had the same problem with UnavailableException, but worked fine with java.net.MalformedURLException (subclass of IOException). Does anyone have any idea on this?
Thank for your help.
Regards,
Yuqing
[ January 29, 2002: Message edited by: Yuqing Zhu ]
 
Yuqing Zhu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another thing should be mentioned for my pre post:
I changed line 4 to
throw new ServletException(new FileNotFoundException())
and comment out page-error for ServletException, the io.html is shown.
Thanks,
Yuqing
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I understand the API, the UnavailableException has a special meaning to the servlet container so it is probably caught elsewhere.
Bill
 
Yuqing Zhu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks William.
I agree UnavailableException is handled in some special way by container. But when I add a <error-code>503</error-code> in web.xml, all UnavailableException is redirect to my desired page. I believe that's <error-code> doing its job. So I think this maybe a work-around.
But how about IOException? As someone had success experience on it, so there must be something wrong in my codes, would anyone has some success codes pasted here, thanks.
Also funny enough, if I wrap UnavailableException in a ServletException, get rid of error-page for ServletException in web.xml, it works fine. So it seems only ServletException and RuntimeException work with <error-page> handling in my experience.
Regards,
Yuqing
[ January 29, 2002: Message edited by: Yuqing Zhu ]
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if you wrapped those other exceptions in a ServletException?

I have never tried this, but you seem to think ServletExceptions and its subclasses are the ones that are appropriately handled by the container (which is probably correct).

[ January 29, 2002: Message edited by: Mike Curwen ]
 
Yuqing Zhu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mike. It did work if I wrap IOException in ServletException.
But as service() method declares throwing IOException, the container should handle it directly with error-page mechanism instead of leaving it out, shouldn't it!
Regards
Yuqing
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The service method throws IO and Servlet Exceptions, but who says the container has to handle those the same? In fact, I think you've proven in an indirect way, that they don't.

It seems that only ServletException or a subclass of this exception are handled by the 'error page' mechanism of the container.

Kinda sucky.

And perhaps I'm wrong, and there is something else going on.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic