aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Pg 556 Exception scenarios answers. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Pg 556 Exception scenarios answers." Watch "Pg 556 Exception scenarios answers." New topic
Author

Pg 556 Exception scenarios answers.

Arun
Ranch Hand

Joined: Oct 03, 2003
Posts: 40
Hello all,
I could not find answers to all the scenarios in page 556, here is a compilation of answers(mine and borrowed from forum). Please post your comments if anything is wrong:

1. A message-drive bean's onMessage() method catches an application exception. Can it rethrow the application exception to the container?
-- No, the onMessage() method does not declare any application exceptions and hence cannot throw the application exception. It can wrap the exception in a runtime exception and rethrow it.

2. A session bean using CMT has a method marked with the NotSupported transaction atrribute While the method is running. the bean calls setRollbackOnly() on its context. will this cause an exception? What kind?
-- Yes, it will cause an exception. It will be an illegalStateException.

3. A message-drive bean, in the onMessage() method, calls getCallerPrincipal(). What happens?
-- Again, an illegalStateException is thrown

4. A session bean using CMT has a method marked with the Madatory transaction attribute. The client calling the method is not in a transaction. What happens?
-- TransactionRequiredException/TransactionRequiredLocalException is thrown.

5. A bean realizes it can't commit a transaction, but it doesn't want the client to get an exception. What can the bean do?
-- Call the setRollBackOnly method and simple suppress the application exception.

6. A bean wants the client to get an application exception, but the bean still wants the transaction to commit. What should the bean do?

-- Simply throw the Application exception as is. It does not have to do anything more.
Regards.
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
Perfect
Jonny Andersson
Ranch Hand

Joined: Sep 07, 2004
Posts: 87
Thank you for having started this thread! And now about one and a half year later do I try to activate it again from its passivated state because I like it and have a few comments ...

1) Yes, but if the exception is wrapped should it be wrapped as an EJBExcpetion which of course is a RuntimeExcpetion. Alternatively, if the circumstances is appropriate or permits it, could it not just consume the exception?

4) Because they said client would I have answered TransactionRequiredException if I must choose one (on the exam for example) because client if not more exactly specified is a someone that is calling the method remotely.

Maybe someone else have more comments of valuea to add?
[ June 23, 2007: Message edited by: Jonny Andersson ]

Truly agile Java application developer with Extreme Programming and high quality craftsmanship
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Pg 556 Exception scenarios answers.