• 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

Using RemoteException and EJBException

 
Bartender
Posts: 2419
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On p.58 of Frits's notes, there are two guidelines about handling system exceptions:
"1. If the EJB method performs an operation that results in a checked exception that the bean method cannot recover, the bean method should throw the EJBException that wraps the original exception."
My comment : can we throw RemoteException that wraps the original exception instead?

"2. Any other unexpected error conditions should be reported using the EJBException."
My comment : can we throw RemoteException instead ?

I am reading Head First EJB 2.0 for fun now. On p. 539 of the book, it says a rule "RemoteException goes to remote clients , EJBException goes to local client".
It says "RemoteException is for remote client only.... EJBException is for local clients only."

Is the rule applied to EJB 3.0? In EJB 3.0, is there any clear guideline when the bean should throw RemoteException and when the bean should throw EJBException.
For example, if the bean fail to obtain a database connection or fail to look up in JNDI, which exception the bean should throw ? RemoteException or EJBException ? Or it doesn't matter.
 
Enthuware Software Support
Posts: 4818
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himai Minh wrote:On p.58 of Frits's notes, there are two guidelines about handling system exceptions:
"1. If the EJB method performs an operation that results in a checked exception that the bean method cannot recover, the bean method should throw the EJBException that wraps the original exception."
My comment : can we throw RemoteException that wraps the original exception instead?

"2. Any other unexpected error conditions should be reported using the EJBException."
My comment : can we throw RemoteException instead ?

I am reading Head First EJB 2.0 for fun now. On p. 539 of the book, it says a rule "RemoteException goes to remote clients , EJBException goes to local client".
It says "RemoteException is for remote client only.... EJBException is for local clients only."

Is the rule applied to EJB 3.0? In EJB 3.0, is there any clear guideline when the bean should throw RemoteException and when the bean should throw EJBException.
For example, if the bean fail to obtain a database connection or fail to look up in JNDI, which exception the bean should throw ? RemoteException or EJBException ? Or it doesn't matter.



Use of RemoteException for explicitly throwing it has been deprecated. Beans now neither declare this exception in their throws clause nor do they throw it explicitly in any case. As per Section 4.9.6:


EJB 1.0 allowed the business methods to throw the java.rmi.RemoteException to indicate a non-application exception. This practice was deprecated in EJB 1.1—an EJB 1.1 or EJB 2.0 or later compliant enterprise bean should throw the javax.ejb.EJBException or another RuntimeException to indicate non-application exceptions to the container (see Section 14.2.2). An EJB 2.0 or later compliant enterprise bean should not throw the java.rmi.RemoteException from a business method.



The clients on the other hand will automatically receive RemoteException, EJBException, or EJBException depending on how they are invoking the bean and what exception does the bean actually throw.

HTH,
Paul.
 
Himai Minh
Bartender
Posts: 2419
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul, thanks for your answer.
So, does it mean java.rmi.RemoteException is not used in any bean method any more ? Should we only limit the usage of RemoteException in RMI only?
In this EJB 3.1 exam, will we be asked under what circumstances we should use RemoteException ?

The specification says "As EJB 2.0 or late compliant EJB should not throw java.rmi.RemoteExceptio from a business method". Does it mean with EJB 3.1, a bean must only throw EJBException for a system exception or any other application exceptions ( eg FileNotFound, IOException and etc)?

 
Paul Anilprem
Enthuware Software Support
Posts: 4818
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himai Minh wrote:Paul, thanks for your answer.
So, does it mean java.rmi.RemoteException is not used in any bean method any more ? Should we only limit the usage of RemoteException in RMI only?
In this EJB 3.1 exam, will we be asked under what circumstances we should use RemoteException ?


When you say "use", I am not sure what you mean. As I explained above, you need to know that a bean never explicitly throws RemoteException. RMI is completely transparent to the beans. It is not required for this cert either. So not sure what you mean by limit the usage in RMI.
However, you need to know when may a client receive a RemoteException. You may consider it a "use". Depends on your perspective.
 
Himai Minh
Bartender
Posts: 2419
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To clarify my post, in RMI, a remote method throws java.rmi.RemoteException. A client application catches that RemoteException.

According to the spec, in EJB 2.0 or later, a bean should not throw RemoteException from any business method.

So that means a bean method should only throw an application exception or EJBException as a system exception ? It seems to me that with EJB 3.1, a bean method should never throw RemoteException to the client. The client of the bean catch the application exception thrown by the bean or an EJBException thrown by it.

According to Frits's notes, p.60 , the container may throw a RemoteException to the client. Or, the communication subsystem may throw a RemoteException to the client.

 
reply
    Bookmark Topic Watch Topic
  • New Topic