• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

handling errors

 
Srinivas Ramgopal
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

In case of a service development wherein the service could be called by other services in the workflow, is it okay to handle java.lang.Error and runtime exceptions inorder to handle the flow gracefully (though Sun does not recommend so, I have been reading few latest articles in web that recommend otherwise).
Thus I would like to know your views.

Thanks in advance for your valuable input and time.

Regards.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34669
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Srinivas,
How would the callers of your service know that something went wrong? I would prefer to let them catch the exceptions if it is important to them.

Note that catching Error is even more dangerous than catching RuntimeException. Errors are things that hard to recover from.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be inclined to catch as much as I could and throw application specific exceptions, but there are some errors that probably mean the JVM is so messed up that your attempt to throw something new won't work either.

What kind of environment are you running in? It's probably good to have some kind of service redundancy through load balancing and maybe even self healing restarts. In EJB land a service is just a thread within the container. If one dies, the container will likely start another.

In Forte 4GL (not Java) we had services that could automatically restart when they crashed and clients that could automatically retry. Crash, restart and retry could go on forever if the client is passing bad data that causes the crash, so even that has to have limits, eg only "n" retries.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic