chaitu chaitu
asked on
why Exception block is calling instead of EJBException block
i am calling one method from controller to ejb.in the EJB addEmployee if flag is true i am throwing exception saying that "match not found" and intrun it will call EJB catch block and then it should call controller EJBException block but it is calling Exception block;why it so??
controller
********
public void addEmployee()
{
try
{
remote.addEmployee();
}
catch(EJBException e)
{
System.out.println("match not found");
}
catch(Exception e)
{
}
}
EJB
*****
public void addEmployee() thows EJBException
{
try
{
//SOME BUSINESS PRCOESS;
if(flag)
throw new EJBException("match not found")
}
catch(EJBException e)
{
throw new EJBException("match not found")
}
catch(Exception e)
{
}
}
controller
********
public void addEmployee()
{
try
{
remote.addEmployee();
}
catch(EJBException e)
{
System.out.println("match not found");
}
catch(Exception e)
{
}
}
EJB
*****
public void addEmployee() thows EJBException
{
try
{
//SOME BUSINESS PRCOESS;
if(flag)
throw new EJBException("match not found")
}
catch(EJBException e)
{
throw new EJBException("match not found")
}
catch(Exception e)
{
}
}
Probably because the exception you throw is not a EJBException or a subclass of it.
ASKER
in EJB it is calling throw new EJBException("match not found") but in controller it is not calling EJBException block..
ASKER
tell me one thing can i write like this
if(flag)
throw new EJBException("match not found")
if(flag)
throw new EJBException("match not found")
> tell me one thing can i write like this
you can
Check the type of the exception. If you're calling a remote object then its probably getting wrapped in something like a RemoteException
you can
Check the type of the exception. If you're calling a remote object then its probably getting wrapped in something like a RemoteException
ASKER
this is remote method.
public java.util.Hashtable addEmployee(Employe emp) throws RemoteException;
so how can i avoid this??
ASKER
so now i watn to throw EJBException in the method so now i changed method to
public java.util.Hashtable addEmployee(Employe emp) throws RemoteException,EJBExcepti on ;
public java.util.Hashtable addEmployee(Employe emp) throws RemoteException,EJBExcepti
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry it retruns void ;;
ASKER
catch the RemoteException means i should use the getCause() method in catch(Exception e) block;;
ASKER
if i write my own userdefined exception also same thing is happening
catch(RemoteException e)
{
Throable cause = e.getCause();
}
{
Throable cause = e.getCause();
}
Any kinds of exceptions thrown remotely will be wrapped up into remote exceptions and thrown by the container, I guess.
ASKER
if i write my own checked exception then its working fine;;
>> if i write my own userdefined exception also same thing is happening
>> if i write my own checked exception then its working fine;;
What's the difference b/w these two?
>> if i write my own checked exception then its working fine;;
What's the difference b/w these two?
ASKER
in my first post i have made a mistake now its working fine;