Hi,
Being new to EJB development i am facing some problems i am sure some of you will be able to help me.
The configurations are
Application Server: IPlanet Application Server 6.0 SP3
We have a user defined exception called UserException which derives from RemoteException one of the method(innerMethod) which is inside aEJB but not a remote method(remoteMethod) throws this UserException our remoteMethod throws only RemoteException no other exception
code is something like
public class MyEJB {
Public remoteMethod() throws RemoteException {
innerMethod();//call inner method
}
Public innerMethod() throws UserException {
//some code which may throw UserException
}
}
public class UserException extends RemoteException
{
///some code
public int getErrorCode()
{}
}
public class MyEJBCallingClass {
public void myEJBCallingMethod()
{
try{
//call ejbs
}catch(remoteException re){
}
catch(UserException ue){
//check for the error code
}
}
We have coded innerMethod so that it puts a code inside the UserException before throwing this Exception this error code is being checked by myEJBCallingMethod to find out which is the error that has happened in the EJB.
But what is happening is that when the UserException is thrown by the innerMethod the myEJBCallingMethod gets ServerException and not the UserException so the error code can't be checked as it's the method of UserException but we get ServerException and the ServerException encaptulates the stack trace for UserException.
The problem is that the error code can't be checked by the myEJBCallingMethod as it dosen't gets UserException
Do anybody know whats wrong with the above code ?
Why UserException is not thrown from the MyEJB ?
What's the right way for throwing User defined exception from the EJBs.
any help will be appreciated.
-Ashish.
-
Exception Handling in EJBs (3 messages)
- Posted by: Ashish Agrawal
- Posted on: February 06 2002 23:52 EST
Threaded Messages (3)
- Exception Handling in EJBs by Tony Brookes on February 07 2002 00:11 EST
- Exception Handling in EJBs by Hemant Khandelwal on February 07 2002 23:29 EST
- Exception Handling in EJBs by Ashish Agrawal on February 08 2002 17:58 EST
-
Exception Handling in EJBs[ Go to top ]
- Posted by: Tony Brookes
- Posted on: February 07 2002 00:11 EST
- in response to Ashish Agrawal
UserException shouldn't extend RemoteException (treat that type as "special."
Rather, UserException should extend Exception (in this case anyhow).
Youre remoteMethod() should declare that it throws UserException. All the EJB spec mandates is that your remote methods must throw RemoteException. It doesn't mandate they must ONLY throw RemoteException.
HTH
Chz
Tony -
Exception Handling in EJBs[ Go to top ]
- Posted by: Hemant Khandelwal
- Posted on: February 07 2002 23:29 EST
- in response to Ashish Agrawal
Hi Ashish,
"A ServerException is thrown as a result of a remote method call if the execution of the remote method on the server machine throws a RemoteException."
This means that if a RemoteException or its sub-class is thrown from the server, rmi-runtime will wrap this exception in ServerException and will marshall the ServerException on the client side. This is how RMI marshalls RemoteException and its sub-classes. So an the client side you will receive ServerException in such cases.
There is field *detail* inside the ServerException class that actually represents the RemoteException thrown on the client side. In *myEJBCallingMethod()* in *MyEJBCallingClass* you can catch this ServerException and from the field *detail* you can perform error-code checking.
Regards,
Hemant
ServerTeam,
www.pramati.com
-
Exception Handling in EJBs[ Go to top ]
- Posted by: Ashish Agrawal
- Posted on: February 08 2002 17:58 EST
- in response to Hemant Khandelwal
Thanks For the help i have done this and this works.