• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do we handle TransactionRollBackException?

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a system exception so it should means something bad really happened rather than normal exception case in our application. However, I do see some codes that do catch this exception and do some special processing.

I just wondering if this exception could means something "normal" - just like application exception (CreateException, FinderException) that the application could and should handle gracefully?
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this rollback exception to create an entity bean. It has a compulsory relation with another bean, connected via an ID field.

The first bean is created at ejbCreate(). However completion rely on the success of ejbPostCreate() where the related bean is to be created. However, if the latter fails, then rollback kicks in.

I can't really say such failure is normal, although it is handled gracefully.

Incidentally, I read from some pattern site that says that exceptions should not be used to substitute if-else logic. That could be a fruit for thought for you to decide whether an exception could be treated as "normal".

I do have a method called getParent() that throws my own NoParentException when the object it belongs to could not get any more parent, e.g. when it is already the root. It used to return a null for this case, but I ended up with a lot of NullPointerException. As you know NPE doesn't require a mandatory try-catch section. Now, with the NoParentException, I don't have to worry over forgetting to check for null.

My inflated 0.02 ... rupee, yen, rupiah, cents, sen, whichever is lowest.

Originally posted by Alec Lee:
This is a system exception so it should means something bad really happened rather than normal exception case in our application. However, I do see some codes that do catch this exception and do some special processing.

I just wondering if this exception could means something "normal" - just like application exception (CreateException, FinderException) that the application could and should handle gracefully?

[ April 19, 2005: Message edited by: Ken Loh ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!