• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet filter throw RuntimeException

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a servlet (inside a web app) filter throws run time exception in its doFilter(..) method, will the web app basically be down ?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, the request which caused that error will get a 500-level response code. The web app will continue to run.

Of course if every request causes a RuntimeException then it will appear to the user that the web app is down, even though it is running as designed.
 
Hilda Stone
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.  But user can only get to the destinaton page of servlet AFTER it passes the filter.  If RuntimeException is thrown in filter how can user get to the page ?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He didn't say that the user would get to the page. He said that it would result in a 500 error.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The 500 page and also the 404 page are pages that are displayed when an exceptional condition is handled by the webapp server itself. In the case of the 404 page, the URL cannot be resolved at all ("Page not found").

The default forms (more precisely the templates) of these pages are actually hard-coded into the webapp server. However you can override them and design your own error pages which you then indicate in your webapps' web.xml config file.

You'd do that mostly as a vanity thing, though, since a well-designed webapp shouldn't be relying on error pages as part of the basic program design. But for people who fat-finger manual URLs you might want some cute alternative 404 page.
 
Hilda Stone
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I think the best way to handle the case when an exception is thrown during filter's doFilter method should be --- just log the error information and let it pass to next filter in filter chain.  This should make more sense than send it to 500 error page, right ?  See, if we get exception in doFilter, it doesn't mean we shouldn't move on to the next filter.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An exception in a filter usually means a bug in the program, so I don't think your approach is the best course. The best curse would be to figure out why the exception is happening and make sure that out doesn't.

If the web app can operate without the filter being applied, why is the filter there in the fist place?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic