I have a question regarding 'throw EJBException' from a business method. In P.543 of HF EJB, Bean Provider's responsibilities (3), it says: " If your business logic catches an exception the client is not expecting, wrap it and rethrow it as an EJBException".
what about Remote clients??? Do we have to throw RemoteException??? thanks in advance shanthisri
But I've one more question regarding the "Bean provider's responsiblities" 1 and 2 in the page 542. Is the given code a "bean's code " or "the client's code"? If it is a bean's code ,how can we catch a RemoteException in the code?? Thanks in advance shnthisri
Whenever you're calling create/finder on a home interface stub, you have to catch the RemoteException because all the methods of Remote home interface throws RemoteException.
This is true even if this code is in a business method of a bean. For example, if you have BeanA.methodA looking up BeanBHome (using JNDI) and then calling either create/finder on the BeanBHome, you have to catch the RemoteException. Here BeanA becomes client for BeanB.
RemoteException is client side. It must be caught by the client. If you develop a bean, you don't care about remote exceptions, unless (as Ankit said) you access another remote bean from your bean's code. In this particular situation, you have to catch RemoteException as any checked exception (just to remind you for the exam, RemoteException is a checked exception, but is considered as a system exception, with corresponding consequences (rollback, log, bean discard and so on...))
What I would add to Ankit code is that it's not limited to create/finder methods. Any method from a remote interface (component or home) must declare a RemoteException, so as a client you must catch it or declare it (but don't declare it in a bean code!!!)