my dog learned polymorphism
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Can a stateless bean throw a remote exception (Enthuware)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Can a stateless bean throw a remote exception (Enthuware)?" Watch "Can a stateless bean throw a remote exception (Enthuware)?" New topic

Can a stateless bean throw a remote exception (Enthuware)?

Jarrod Felino

Joined: Nov 15, 2008
Posts: 26
This is from Enthuware Test 1 Q1:

The important thing to remember is that FinderExceptions, CreateException, and RemoveException are checked application exceptions and must be declared in the throws clause of the method.

Also, beans are not allowed to throw RemoteException. It is the container's responsibility to throw it to the client if the client is a remote client.

Therefore, this code can only throw an EJBException, which is a RuntimeException.

However I wrote a quick test and the container (JBoss) did not have an issue with it:

Am I missing something here or is this merely a recommendation of the EJB3 specification?
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1710
In EJB 3.0 with @Remote annotation business methods need not to to throw

If you throw, its no harm but in fact it is no required.
[ November 30, 2008: Message edited by: Chandra Bhatt ]

Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3636
There is no Java langauge requirement that beans cannot throw RemoteException. So when you say that Beans are not allowed to throw RemoteException, it is not the compiler but the EJB specification that you are talking about. For example, if you say that a bean method is not allowed to call System.exit(0);, it means that the EJB specification forbids it, not Java language/compiler. So you can call System.exit(0) but, obviously, it would be a wrong thing to do.

Having said that, your confusion is valid and further clarification has been added to the explanation.

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
I agree. Here's the link:
subject: Can a stateless bean throw a remote exception (Enthuware)?
It's not a secret anymore!