• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quiz on method exception declaration

 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a little quiz I've just made up.

For any CMT bean class, which method(s) must declare at least one exception? Exclude from your answer any implementations of interface methods.
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you are talking about the bean class, not the interface class,
the spec requires that for CMP entity beans:

- every ejbCreate method must declare it throws CreateException
(the spec requires it but containers don't seem to enforce it,
I've noticed)

- ejbSelect method declarations must throw FinderException
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, that's right. And for remote clients, both methods must declare RemoteException. Declarations would look like these:


public PrimaryKeyClass ejbCreate<METHOD>(args) throws javax.ejb.CreateException, java.rmi.RemoteException {}

public abstract type ejbSelect<METHOD>(args) throws javax.ejb.FinderException, java.rmi.RemoteException;

The return type of ejbSelect must of course correspond to a cmp-field type or a cmr-field type.
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, I don't think that RemoveException stuff is correct. Back in the EJB 1.1 days I think the bean provider's implementation methods had the option of declaring RemoteException, but in EJB 2.0 the spec very explicitly says to NOT declare remote exceptions.

The reason for this is that the client receives RemoteException not because your code generated, but because either the server generated it, or the RMI-IIOP transport layer generated it (e.g. during a network partition).

If you declare a RemoteException on your implementation methods, then according to the spec your LOCAL interface methods would be required to also declare RemoteException. RemoteException isn't a system exception, and the interface declarations must allow anything declared to be thrown from the implementation methods to come through.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What am I thinking? Of course you must never declare RemoteException in your bean class! I think my brain must have thrown an exception ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic