• 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

best way to handle errors across servlet and javascript

 
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the comments
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic