• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

page 543 (wrapping and rethrowing as an EJBException)

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, I agree with Rahul
 
shanthisri mocherla
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!)
 
What's gotten into you? Could it be this tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic