Meaningless Drivel is fun!
The moose likes EJB and other Java EE Technologies and the fly likes problem in throwing Exception from Bean 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 "problem in throwing Exception from Bean" Watch "problem in throwing Exception from Bean" New topic

problem in throwing Exception from Bean

Poornachandran R
Ranch Hand

Joined: Sep 11, 2002
Posts: 47
Dear all,
Following lines will depict my situation.
try {
invokes...the m1 method in the EJB Bean.
} catch(ABCException ae) {
System.out.println("in abc catch");
} catch(RemoteException re) {
System.out.println("in remote catch");
EJB Bean
m1() throws ABCException, RemoteException {
dao invoking code
m1() throws ABCException {
try {
db access code here....
} catch(Exception e) {
throw new ABCException("relevant msg");
If there is an error in throws the ABCException to Bean and inturn the same is thrown to Servlet.
But the problem is, In Servlet...i am getting the output....
"in remote catch"
Can anybody say why it is so ?
Note : My ABCException extends EJBException.
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
This is the expected behavior.
The problem is, EJBException is a subclass of RuntimeException and hence NOT considered an application exception by the container.
If you want the exception to be propagated to (Servlet)client in its original shape and form, it has to be an application exception. EJB spec requires all application exceptions to be direct subclass of java.lang.Exception.
[ April 30, 2003: Message edited by: Ajith Kallambella ]

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
I agree. Here's the link:
subject: problem in throwing Exception from Bean
It's not a secret anymore!