This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes a thumb of rule of Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "a thumb of rule of Exception" Watch "a thumb of rule of Exception" New topic
Author

a thumb of rule of Exception

Hai Lin
Ranch Hand

Joined: May 23, 2004
Posts: 79
Hi Guys,
I did a summary after reading exception of HFEJB --- all the RuntimeException (such as nullpointerexception, indexoutofarrayexception...) plus RemoteException thrown by bean, the remote client will only get RemoteException while the local client will only get EJBException. As for those exceptions thrown by container or stub, need do more detail analysis.

Is my summary right? It it is, then it will help us to remember those various exceptions
Any suggestion is welcomed.

Hai
Sandesh Tathare
Ranch Hand

Joined: Jun 22, 2003
Posts: 82
Hai,
U r correct when you say:
For all the RuntimeException - the remote client will only get RemoteException while the local client will only get EJBException.

But can you explain what do you mean by:
As for those exceptions thrown by container or stub, need do more detail analysis.


Regards,<br />Sandesh<br />(SCJCP, SCWCD, SCBCD - 99%, OCP-1)<br /> <br />Either find a way or create one.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
This is correct. If you want more information on exception handling, you can also have a look at my cheat sheet which is supposed to be a more digestable view of the spec, at leats I hope so

Check it out at http://www.valoxo.ch/jr/cheatsheets.html (Exception handling)


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
RemoteException must never be thrown by a bean.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Originally posted by Roger Chung-Wee:
RemoteException must never be thrown by a bean.


Thanks Roger, that's correct, I have overlooked that one in Hai's post.

A RemoteException can only be thrown by the container when:
1. the bean throws a system exception (a RuntimeException or a checked exception wrapped in an EJBException) AND
2. there is no caller transaction available

See my cheatsheet for more details...
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
For session and entity beans, RemoteException is thrown regardless of the caller transaction.

If a business method of a CMT session bean or a CMT entity bean throws a non-application exception, the container will then always throw RemoteException to a remote client.

If the method was running with an unspecified transaction context or in the context of a transaction which the container had started immediately prior to running the method, RemoteException will be thrown.

If the bean method was running in the context of the caller�s transaction, javax.transaction.TransactionRolledbackException will be thrown. As this exception IS-A RemoteException, I am able to say that RemoteException is always thrown.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Right Roger, that summarizes well (and in plain english) the lower part of my cheatsheet

The only point I forgot to clarify in my previous post (and you did it well, thank you for that ) is that TransactionRolledbackException extends from RemoteException and thus my statement should have been:

A RemoteException (or subclass thereof) is always thrown by the container when the bean throws a system exception (a RuntimeException or a checked exception wrapped in an EJBException) to remote clients.

Thanks for the clarification
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a thumb of rule of Exception
 
Similar Threads
why the bean class does not implement remote interface
Exceptions
Is this correct? Exception question
System Exception Confusion
Regarding throwing java.rmi.RemoteException