• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exceptions

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a little bit confused about the way that the container handles exceptions thrown by the bean. Does the following sound right?
Suppose there is a remote client with a remote component interface for a stateful session bean that has just been removed. The client tries to call a business method on the removed bean. Since the bean doesn't exist anymore, the client is going to get an exception, probably a java.rmi.RemoteException.
I am wondering why the client doesn't get a java.rmi.NoSuchObjectException. Or does it?
I guess one point that confuses me has to do when a bean throws a system exception. It often means that the container is going to throw java.rmi.RemoteException to the client, but not always that exception? For example, if a CMT bean calls getUserTransaction on its context, the bean will throw an java.lang.IllegalStateException to the container, but now does a remote client get that same exception or just always a RemoteException when things go wrong?
C Arthur
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be i'm wrong. but i think if a CMT bean calls getUserTransaction will throw IllegalStateException it's mean that bean instance *can not* be run
it's mean that bean miss config or something. but if you got NoSuchObjectException it's mean caller is wrong.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EJB spec is not very forthcoming about the exception thrown by the container. For example if there is DuplicateKeyException, the container might throw the same exception to the client or it might throw CreateException. I hate it when the spec doesn't define a rigid rule and gives so much room to the container which leads to all sorts of confusion.
- walk rustin
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In th efirst case , it will throw java.rmi.NoSuchObjectException only , not the RemoteException . And in the second case , it throws IllegalStateException . I never tried this as i am new to EJB . this is my bookish knowledge .
Actually IllegalStateException is a subclass of RunTimeException whoch should mean that remoteException should be thrown to the client . Any help here guys?
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ramakrishan wrote:


In th efirst case , it will throw java.rmi.NoSuchObjectException only , not the RemoteException . And in the second case , it throws IllegalStateException . I never tried this as i am new to EJB . this is my bookish knowledge .


In fact, it will throw a Remote Exception, because the bean itself has been removed. see HFE p.559.
You get a NotSuchObjectException just in the case where the component interface has been removed or is no more available.
Regards,
Cyril.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In fact, it will throw a Remote Exception, because the bean itself has been removed. see HFE p.559.
You get a NotSuchObjectException just in the case where the component interface has been removed or is no more available


But on p.552 of HFEJB under NOSuchObjectLocalException, it says that Container throws this exception to client when the client invokes a method on a local home or components and the bean has already been removed (either through a previous client call to remove(), or because the Container killed the bean due to an exception, stateful bean timeout, or to reduce the size of the pool". Somehow it contradicts the one on p559.
Also from the EJB 2.0 spec 18.3.5:
If a client makes a call to a session object that has been removed, the Container should throw the java.rmi.NoSuchObjectException (which is a subclass of java.rmi.RemoteException)to a remote client, or the javax.ejb.NoSuchObjectLocalException to a local client.
I believe the answer will be NoSuchObjectException if I were asked to choose between NoSuchObjectException or RemoteException.
Joyce
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure my cheat sheet about Exception handling might help, but just in case, you can get ithere
 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Valentin, the cheat sheet looks good.
 
Ramakrishna Allam
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if a CMT bean calls getUserTransaction() method on its context , EJB Specification says that it throws IllegalStateException , which is a RunTimeException . So , if the client is remote , will that throw a RemoteException or not!! looks strange..
 
reply
    Bookmark Topic Watch Topic
  • New Topic