This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

problem in throwing Exception from Bean

Poornachandran R
Ranch Hand

Joined: Sep 11, 2002
Posts: 47
Dear all,
Following lines will depict my situation.
Servlet
-------
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
}
DAOImpl
-------
m1() throws ABCException {
try {
db access code here....
} catch(Exception e) {
throw new ABCException("relevant msg");
}
}
If there is an error in DAOImpl...it 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.
Poorna
Ajith Kallambella
Sheriff

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).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem in throwing Exception from Bean
 
Similar Threads
OO Design issue with Data and RMI instance??
Session Beans and SessionBean interface.
java.rmi.RemoteException: NullPointerException
java.net.UnknownHostException occurred when invoke Clustered EJB
Naming.Lookup and Rebind