I came across this question in ejbcertificate mock exam Which of the following statements regarding message-driven bean exception handling are true? 1. Message-driven beans throw both application exceptions and system exceptions. 2. If a system exception is thrown by a method, the transaction is always rolled back by the container. 3. If a system exception is thrown by a method, the bean instance is always discarded. 4. If a system exception is thrown by a method, the client does not receive the exception. 5. If an application exception is thrown by a method, the client receives the exception. Answer given: 3, 4. I did not understand why option 4 is correct. I thought the client will receive a EJBException/RemoteException when a system exception occurs.
The client knows nothing of the MDB as it only talks to the Destination. When an MDB method throws an exception, the container will always log the exception, rollback the transaction (if necessary) and destroy the MDB instance. Should the client then send another message to the Destination, the container can pull another MDB instance from the pool to service the message.
MDB can throws System exception only. MDB can not throws application exception and can not throws exception to client because MDB don't have any client. MDB run in CMT CASE 1 : Bean method runs in the context of a transaction that the Container started immediately before dispatching the method. This case happens with Required attribute. If This method is throws System exception Then In Container Log the exception or error. Rollback the container-started transaction. Discard instance. Case 2 : Bean method runs with an unspecified transaction context. This case happens with the NotSupported. IF This method is throws System Exception. Then In container Log the exception or error. Discard instance. MDB run in BMT Bean is message-driven bean. If this method is throws System exception Then Log the exception or error. Mark for rollback a transaction that has been started, but not yet completed, by the instance. Discard instance.
Java Developer, Thailand
Without deviation from the norm, progress is not possible - Zappa. Tiny ad: