In JavaBeat's site, I found this mock question around exceptions:
3)choose correct statement
1.methods of business interface may throw java.rmi.RemoteException 2.Methods of local and local home interface may throw java.rmi.RemoteException 3.Methods of web service end points interface may throw java.rmi.RemoteException 4.Methods of remote and remote home interface must not throw application exception
The answer is 3 but I think it's 1. Am I wrong ?
For me, 1 is OK because the spec says (4.6.6) "The remote business interface is not required or expected to be a java.rmi.Remote interface. The throws clause should not include the java.rmi.RemoteException. The methods of the business interface may only throw the java.rmi.RemoteException if the interface extends java.rmi.Remote."
2 is wrong.
3 is wrong too because the spec says (4.6.11) "This means that their argument and return values must be of valid types for JAX-RPC, and their throws clauses must include the java.rmi.RemoteException. The throws clause may additionally include application exceptions." It doesn't say "may" but "must" !
Methods of the "Remote" Business interface may throw a RemoteException indeed. But the question does not state whether it is remote or Local. Local interfaces may never ever ever ever declare RemoteExceptions. If you try doing it the container will crash by laughing at you.
Benoît de Chateauvieux
Joined: Aug 10, 2007
Many thanks, Sven !
Joined: Feb 13, 2008
Well it just seems logic to me. I'm currently learing for the EJB 2 exam but I doubt the whole logic behind local-> ejbException remote-> RemoteException has changed in ejb3.