• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

servlet filter throw RuntimeException  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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 ?
 
Sheriff
Posts: 24288
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 16
  • Mark post as helpful
  • send pies
  • 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 ?
 
Marshal
Posts: 67255
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Bartender
Posts: 20562
120
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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: 16
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 67255
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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?
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!