Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unchacked Exception Propagation

 
Sajid Moinuddin
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
How can I propagate my unchecked exceptions to ejb-clients?
Say, In a business method of EJB, I want to throw StaleRecordException.
Now, I want my client to be able to catch this exception if he wants but I don't want to force him to catch this exception by making it checked.
Actually I want to create exceptions like DuplicateKeyException. DuplicateKeyException is also an unchecked exception but it does propagate to my client.
When I am throwing StaleRecordException which is RuntimeException,
The exception does not propagate to the client as expected.
How can i have unchecked exceptions that can propagate to client unmodified?

regards,
Sajid
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple rule for exceptions: If you want your exception to be propogated back to the client, make it a checked exception. If you're making your exception as unchecked exception, the client will get the EJBException.

Actually I want to create exceptions like DuplicateKeyException. DuplicateKeyException is also an unchecked exception but it does propagate to my client.


DuplicateKeyException is NOT unchecked. It is subclass of javax.ejb.CreateException, which is subclass of java.lang.Exception. So both the CreateException and DuplicateKeyExceptions are checked exceptions. Refer to API Docs for more details.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic