• Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt regarding exception handling strategy in web application with out using any framework  RSS feed

 
Ayan mallick
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some doubt regarding usage of exception in web application. what i have learnt form here that if there is a chance to recover from exception then use checked exception.

Now could anyone give some example like what sort of recovery we trying to mean here. If one checked exception arise should i just catch it there log it or print stacktrace and rethrow as runtime exception. or just wrap it in servlet exception and throw it. or catch it and show some error message to user and let the processing go like as it is.

I mean whether to show customer an exception page with proper message and there will be link to get back to application. i have doubt regarding the strategy to apply handling checked exception. or should i declare every exception as runtime exception and show an exception page and there will be a link to come back to the application and continue.

or just write one utility class where i will analyse the exception and redirect it to exception page rather than defining it in web.xml. looking for suggestion.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't find it very useful to show a user a stack trace - they just panic and forget to write anything down.

The important thing is to log as much information as possible, then decide what the consequence for the servlet should be. A serious problem suggest that the servlet should be take off line with a javax.servlet.UnavailableException which will notify the container.

With a little thought you can create a custom exception that will record more about the state of your application than a NullPointerException (for example).

I also like to use IllegalArgumentException to report bad input to a method.

Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!