• 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

Exception handling - Error Pages or Error attribute?

 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy Ranchers!

Just wondered - what do you think is the "right" choice of handling servlet exceptions?

When in controller (servlet) an exception is raised, you are:

1. Wrapping this exception into runtime one (like ServletException) and defining appropriate error-page in DD (application-wide exception handling),
2. Setting some attribute (like "error") using request.setAttribute("error", DESCRIPTIVE_ERROR_MESSAGE) and preparing your page for showing such errors (i.e. <span class="error">${error}</span>)

Or maybe you prefer some other way?

I suppose the universal answer would be "whatever works for you", but I'm asking this question more in terms of patterns and good habits.

Thanks in advance for your replies!

Cheers!
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that the error-page stuff should be only for unexpected errors. Other kind of recoverable errors like "The item you've chosen has already been sold" or things like that should be displayed via a request parameter.
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Christophe,

I think I will follow your point of view ( I guess it is also consistent with the Struts approach, and their "error" variable after form submit, right?)

Cheers!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pedro Kowalski wrote:I guess it is also consistent with the Struts approach, and their "error" variable after form submit, right?


Yes.
reply
    Bookmark Topic Watch Topic
  • New Topic