Wednesday, December 19, 2007

Runtime Exception or Regular Exception

This is the question that asked often, when should I throw RuntimeException and where should I throw regular Exception, this is the answer:

  • If you exception which is thrown is pure technical exception from which the client can't recover from then throw RunTime Exception in case you run in J2EE server with Transaction Manager set then it would also rollback the transaction. Even that this exception doesn't have to be declared as part of the function exception signature it is advice to declare it so the client would be aware for this exception.
  • If your exception is pure business applicative exception then this exception should be regular not RunTime exception so this exception would be displayed for the user in the end and he would be able to change something to fix it, when throwing this exception in J2EE server with Transaction Manager the transaction doesn't rollback.

No comments:

Links

 
RSS Feeds Submission Directory