i. You catch a checked exception in your ejbActivate method. The method is not in a transaction. (A. Throw an EJBException). Becuase the ejbActivate is a container callback method we cannot throw a checked exception from a method that does not declare the exception. The only thing we should throw from one of the container callbacks of SessionBean is an EJBException
ii. A DivideByZero exception occurs as your business logic is running. You do not have a try/catch for this. (D. Allow the exception to propagate(in other words, duck it).
iii. You throw a CreateException from your ejbCreate() method and you realize that you probably cannot safely complete your transaction (C. Invoke setRollbackOnly()
iv. You catch a checked exception in a business method, and realize that your bean is probably corrupt (C. Invoke setRollbackOnly())
Throw a wrapped EJBException to the container. Because your bean is corrupt. Apart from rolling back the transaction, you would want the container to kill your corrupt bean. If you just call setRollbackOnly, the container will rollback the transaction, but the corrupt bean would continue processing business logic. So, let your bean throw a wrapped EJBException to the container so that the container can rollback the transaction and kill the corrupt bean and log the exception
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop