Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF Exception doubt

 
Deep Chand
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HF book (page 559) says:

When a client calls remove() on a bean that's already been removed, you'll get the same exception you'd see if you called any other business method on a removed bean - remote clients get RemoteException and local clients get EJBException.

But I thought that the clients should get NoSuchObjectException/NoSuchObjectLocalException for remote & local clients respectively.

Please reply with whether I'm correct or not.

Thanks
Deep
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deep you get same doubts that I get :-)

NoSuchObjectException is subclass of RemoteException

and
NoSuchLocalObjectException is subclass of EJBException

So you are right and they are not wrong either.
Stefan helped me with it at

http://www.coderanch.com/t/160550/java-EJB-SCBCD/certification/Exception-HFEJB

Gemini
 
Deep Chand
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed but if both RemoteException and NoSuchObjectException are the options (possible answers) in the exam then what should we choose? The reason I'm more confused is bcoz HF book also says that Container is not bound to throw the MOST SPECIFIC Exception (e.g., it can throw CreateException instead of DuplicateKeyException)

Thanks
Deep
 
Stefan Guilhen
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think you will get both options in a question because one could argue that both are right and the exam questions are very clear, they avoid such type of confusion.
If I get such a question I would choose NoSuchObjectException because this is what the container is supposed to throw. (see page 379 of the spec). But again, it is a subclass of RemoteException, so it is not wrong to say that the remote client will see a RemoteException.

Regards,
Stefan
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the API, all three remove methods would throw RemoveException if the bean/container does not allow the method to be invoked. A RemoteException/EJBException will be thrown to indicate to a remote/local client that the method invocation had failed due to a system-level failure.

When the client made such a request on the bean, the bean should throw NoSuchObjectException/NoSuchObjectLocalException. This being a system exception, will not be caught & will be propagated to the container. The container will then rethrow this as a RemoteException/EJBException back to the client, depending on whether its a remote/local client.

I think the catch here is that the bean does not throw an exception directly to a client. It throws it to the container & the container throws it to the client.

The part whereby the books says that the client may not get the most specific exception, I guess its refering to the application exceptions rather than system exceptions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic