• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie: How to handle exceptions in ServletContextListener class

 
Daniela Meyer
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there
What would be the best way to handle exceptions in a class implementing a listener interface in a web application?
I am new to J2EE. As I understand, there is no HttpServletResponse available to invoke the sendError() method as my class is not a servlet. So a RequestDispatcher is not available either.
Would I write into a log file? Or what would an experienced ranger suggest?
Thanks for your advice!
Daniela
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be the best way to handle exceptions in a class implementing a listener interface in a web application?
I am new to J2EE. As I understand, there is no HttpServletResponse available to invoke the sendError() method as my class is not a servlet. So a RequestDispatcher is not available either.
right... because you're in a listener... but even if you *could* call sendError() which user would you send the error message to? The error didn't happen to them... it was in the listener.
Would I write into a log file? Or what would an experienced ranger suggest?
Logging it to a file would be an excellent idea -- but it really depends on what the problem is. You need to determine how its best to handle the error. Is this something severe, that should NEVER EVER HAPPEN? Is this just minor, no big deal, don't even need to worry about logging it? Or is this something bad, but not terrible, and you should log it so that if it happens a lot -- you can hopefully track it down and fix it?
Hope that helps...
 
Daniela Meyer
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jessica!
But, what if the problem would have any consequences for the user? How would I inform the user? By throwing a Runtime Exception?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic