Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception handling - Error Pages or Error attribute?

 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic