This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Catching Exceptions" Watch "Catching Exceptions" New topic
Author

Catching Exceptions

Dave Hewitson
Greenhorn

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.
Dave
Susil Parida
Greenhorn

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
http://free.hostdepartment.com/s/susilparida/NestedException.html


Susil Parida<br />HCL Technologies<br />Susil_pp@epatra.com
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Catching Exceptions
 
It's not a secret anymore!