jQuery in Action, 3rd edition
The moose likes EJB and other Java EE Technologies and the fly likes Catching Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Catching Exceptions" Watch "Catching Exceptions" New topic

Catching Exceptions

Dave Hewitson

Joined: Jun 01, 2001
Posts: 27
I'm using EJB 1.0 and need to know how to catch a DuplicateKeyException in my CMP EJB.
My create method only throws CreateException (superclass of DuplicateKeyException) and when I attempt to use the bean to write a record with a duplicate PK, an SQLException is thrown, but by the time the exception reaches my session bean it's turned into this exception: "CORBA TRANSACTION_ROLLEDBACK 0 No; nested exception is: org.omg.CORBA.TRANSACTION_ROLLEDBACK:".
I can see the duplicate error in the stacktrace: it's nested deep within the above one - but I want to show the user the correct error.
Is there a way to do this?
You could argue that I should try and see if the record is already there, but that seems like a bit of an overhead.
TIA for any help.
Susil Parida

Joined: Jan 09, 2003
Posts: 9
There is only overhead is to extract the nested Exception
I would suggest to take out the nested Exception in Session bean and if it is DuplicateKeyException then handle accordingly.
Code is there at

Susil Parida<br />HCL Technologies<br />Susil_pp@epatra.com
I agree. Here's the link: http://aspose.com/file-tools
subject: Catching Exceptions
It's not a secret anymore!