Search your topic in Java2share
Home > SCBCD > SCBCD Question Bank
eXTReMe Tracker

10. Exceptions (SCBCD)

Q: 1 A developer is working on a user registration application using EJB 3.0. A
business method registerUser in stateless session bean RegistrationBean performs the user registration.
The registerUser method executes in a transaction context started by the client. If some invalid user data
causes the registration to fail, the client invokes registerUser again with corrected data using the same
transaction. Which design can meet this requirement?

A. Have registerUser method call EJBContext.setRollbackOnly() method after registration fails.
B. Have registerUser method throw javax.ejb.EJBTransactionRequiredException after registration fails.
C. Have registerUser method throw EJBException without marking the transaction for rollback, after
registration fails.
D. Create an application exception with the rollback attribute set to false and have registerUser method throw
it after registration fails.

Answer: D

Q: 2 Which method always throws an exception when invoked on a
container-managed entity manager?

A. the lock method
B. the close method
C. the flush method
D. the clear method

Answer: B

Q: 3 A session bean's business method throws an exception during execution.
Which two are responsibilities of the Bean Provider when throwing the exception? (Choose two.)

A. For application exceptions, ensure that if the current transaction commits there will be no loss of data
B. For application exceptions, ensure that the current transaction will commit.
C. For system errors, when the client is remote, throw a java.rmi.RemoteException that wraps the original
D. For checked exceptions from which the bean cannot recover, throw an EJBException that wraps the original

Answer: A, D

Q: 04 Which is a correct way of defining a runtime exception as an EJB 3.0
application exception?

A. public class MyAppException extends javax.ejb.EJBException
B. @ApplicationException
public class MyAppException extends java.rmi.RemoteException
C. public class MyAppException extends java.lang.RuntimeException
D. @ApplicationException
public class MyAppException extends java.lang.RuntimeException

Answer: D