The following is a question from Whizlabs mock test:
Which of the following statement is incorrect about how the exceptions are handled in EJBs?
Choose one answer.
a. When a business method of an enterprise bean throws an application exception, the container discards that instance of the bean
b. Message driven beans are not allowed to throw application exceptions to the client.
c. When a business method of an enterprise bean throws an application exception, the container always automatically rolls back the transaction.
d. The class of the exception received by the client is the same as the class of the exception when the bean throws an application exception.
It says: Choice C is the correct answer.
Ofcourse choice C is correct; which implies the statement is wrong and all other statements are correct. But I am not sure whether the choice A is correct or not. Does the container really discard an instance of a bean if it throws application exception?
this question seems ill-formulated, because according to Table 14 of section 14.3.1 in core spec, after applications exceptions the container don't discard instance, but any other type of exception yes.
leonardo segala wrote:this question seems ill-formulated, because according to Table 14 of section 14.3.1 in core spec, after applications exceptions the container don't discard instance, but any other type of exception yes.
I too have the same understanding. In such a case, the statement with choice A is wrong and hence the question should have both choices A, C as the answers. Am I correct?
For option B) an exception wouldn't reach a client because MDB's don't have clients. Do they mean the container?
Also even for option C) which is correct, the case exists where an application exception can be marked as @ApplicationException(rollback=false). This would not cause a rollback. In fact any exception explicitly defined as so by the bean-provider using the @ApplicationException annotation defaults to rollback=false.
Perhaps they should word this question with a code sample or something to eliminate ambiguity.