• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

page 543 (wrapping and rethrowing as an EJBException)

 
shanthisri mocherla
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
 
Rahul Mishra
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, No...

Never Ever throw a Remote Exception from a bean..the reason for throwing an EJB Exception is that its unchecked.


When you throw an EJB Exception, container intercepts it...if its a local client ...it throws EJB EXception or it throws Remote Exception
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, I agree with Rahul
 
shanthisri mocherla
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rahul and Frederic,

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
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Hope this is clear.
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I agree again (I only agree in this topic )

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!!!)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic