aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Remote Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Remote Exception" Watch "Remote Exception" New topic
Author

Remote Exception

raj joe
Ranch Hand

Joined: Mar 17, 2005
Posts: 99
I have the below archiecture.

Action - Session Bean - DAO -DB
My DAO methods throws varies application exceptions.
Thus all these exceptions come to my session bean.

Will my sesion bean throw back all these exceptions to my action?I have declared these application exceptions in the throws clause of my session bean method.

or will sesion bean throw only the remote exeption.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

It depends entirely on what exceptions you decide to throw. I'm assuming your session bean defines your business methods. If that is the case, it probably makes sense to limit possible exceptions these methods can throw to exceptions which have meaning to the functionallity the method is there to perform.

Your DAO layer for example is likely to generate JDBC-type exceptions. But is it appropriate to throw these exceptions from the Session bean? What does a client care that it was a primary key constrain violation, or a invalid number of bound parameters etc. which prevented it creating some type of object in the DB? As far as the client is concerned the operation either works or doesn't, and there's nothing the user can do to fix it, whatever flavour of JDBC-type exception was thrown from the failed operation. Instead you might have your DAO layer throw one type of DAO exception with a simple message, and log the real cause so you can address it.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Application exceptions are checked exceptions, so the container will pass them back untouched to the client.

But bear in mind that some low-level exceptions like SQLException are checked but are unlikely to be welcomed by the client. In such a case, wrap the exceptions in javax.ejb.javax.ejb.EJBException and throw it. The container will catch the exception, log it and throw EJBException to a local client or java.rmi.RemoteException (or subclass thereof) to a remote client or web service client.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Remote Exception