Avatar of chaitu chaitu
chaitu chaituFlag for India

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)
      {
           
      }


}


Java

Avatar of undefined
Last Comment
chaitu chaitu
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Probably because the exception you throw is not a EJBException or a subclass of it.
Avatar of chaitu chaitu

ASKER

in EJB it is calling throw new EJBException("match not found") but in controller it is not calling EJBException block..
Avatar of chaitu chaitu

ASKER

tell me one thing can i write like this

if(flag)
            throw new EJBException("match not found")
Avatar of Mick Barry
Mick Barry
Flag of Australia image

> 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
Avatar of chaitu chaitu

ASKER


this is remote method.
public java.util.Hashtable addEmployee(Employe emp)      throws RemoteException;

so how can i avoid this??
Avatar of chaitu chaitu

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,EJBException ;
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of chaitu chaitu

ASKER

sorry it retruns void ;;
Avatar of chaitu chaitu

ASKER

catch the RemoteException means i should use the getCause() method  in catch(Exception e) block;;
Avatar of chaitu chaitu

ASKER

if i write my own userdefined exception also same thing is happening
Avatar of Mick Barry
Mick Barry
Flag of Australia image

    catch(RemoteException e)
     {
          Throable cause = e.getCause();
           
     }
Avatar of Mayank S
Mayank S
Flag of India image

Any kinds of exceptions thrown remotely will be wrapped up into remote exceptions and thrown by the container, I guess.
Avatar of chaitu chaitu

ASKER

if i write my own checked exception then its working fine;;
Avatar of Mayank S
Mayank S
Flag of India image

>> 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?
Avatar of chaitu chaitu

ASKER

in my first post i have made a mistake now its working fine;
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo