• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a thumb of rule of Exception

 
Hai Lin
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RemoteException must never be thrown by a bean.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic