Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Catching Exceptions

 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic