This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Best Practice for EJB Remote Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "Best Practice for EJB Remote Exceptions" Watch "Best Practice for EJB Remote Exceptions" New topic
Author

Best Practice for EJB Remote Exceptions

Douglas Kent
Ranch Hand

Joined: Oct 06, 2000
Posts: 171
Should the bean class catch all application-level exceptions, deal with them and re-throw EJBException? And thus declare no exceptions in its methods? That way, the remote interface only has to declare "throws RemoteException".

By way of explanation, I am getting an error in the Sun One deploytool verifier that complains thusly:

Error: method [ TrRequest ] does not throw valid application exceptions in Remote/Local interface

thanks!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14573
    
    7

I wouldn't recommend it. My experience is that it's best to make your exceptions be as specific as possible. It helps document what particular things are likely to go wrong, and it allows you to use multiple catch clauses instead of a big ugly single clause with instanceof tests. And that's especially useful since you can capture only the exceptions you want to handle and percolate the others out to somewhere more appropriate.

I even go so far as to provide private inner-class for exceptions specific to objects. Although I can't trap them by name, having a unique exception name adds to the information displayed on the stack trace/debugger. I imagine some may object to that practice, though.


Customer surveys are for companies who didn't pay proper attention to begin with.
Douglas Kent
Ranch Hand

Joined: Oct 06, 2000
Posts: 171
Thanks, Tim. My thought was to wrap all the application exceptions in the EJBException, which will be re-thrown to the client as a RemoteException, who can then interrogate the wrapped exception to determine what happened. Since the client calls only the stub, it seems that is a good way to go...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best Practice for EJB Remote Exceptions
 
Similar Threads
Rules for component interface and home interface
EJB 2.0 Remote Client View
HFEJB common EJBObject SessionBean interface
SessionBean exceptions
Understanding Exception