Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Remote Exception

 
raj joe
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic