• Post Reply Bookmark Topic Watch Topic
  • New Topic

best way to handle errors across servlet and javascript  RSS feed

 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys.
I want to improve the way errors are handled in my software. Below is the current implementation:


This is high maintenance since I need to ensure that the error messages in the servlet and javascript are consistent.
Please let me know all your good thoughts on this.
Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, exceptions in servlets should not be caught and just let propagate outward to the container where an error handler that you establish in the deployment descriptor can handle them in a consistent fashion.

Errors in script I usually handle differently, because they are simply so very different in nature, but you can always make script errors emit that same type of output as your server-side error handler for consistency.
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Generally, exceptions in servlets should not be caught and just let propagate outward to the container where an error handler that you establish in the deployment descriptor can handle them in a consistent fashion.

Errors in script I usually handle differently, because they are simply so very different in nature, but you can always make script errors emit that same type of output as your server-side error handler for consistency.


Thanks. I think that you are referring to using the error codes like so:

I still would like to know how to indicate errors with specific error numbers. Also, for the case when the session is null, in all my servlets, I have to write if session is null then ...
That's the main thing that should be fixed.
Also, one concern is that what if the user made a change while not knowing that the session was expired, then he clicked save. You do not want to automatically redirect. Instead, you want to open a pop up dialog and ask them to login again; just like an email service.

Anyways, please continue to elaborate.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't be throwing exceptions for handling errors that are expected. Exceptions should mean that something unexpected has happened.

And exceptions certainly have no part in security.
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've mixed up the 2 topics.
Here is the improved question: how would I make a common invalid session handler for my servlets?
I guess a possibility if jsf; I hope there is a simpler solution to suggest.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF? That's an entire component framework!

I'd just look into using a filter.
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the comments
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!