?
Solved

why Exception block is calling instead of EJBException block

Posted on 2006-05-06
15
Medium Priority
?
176 Views
Last Modified: 2010-03-31
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)
      {
           
      }


}


0
Comment
Question by:chaitu chaitu
  • 9
  • 4
  • 2
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 16620776
Probably because the exception you throw is not a EJBException or a subclass of it.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16620780
in EJB it is calling throw new EJBException("match not found") but in controller it is not calling EJBException block..
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16620783
tell me one thing can i write like this

if(flag)
            throw new EJBException("match not found")
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 16620791
> 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
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16620805

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

so how can i avoid this??
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16620809
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 ;
0
 
LVL 92

Accepted Solution

by:
objects earned 1500 total points
ID: 16620810
you can't.
catch the RemoteException and use the getCause() method to get the actual exception.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16620811
sorry it retruns void ;;
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16620829
catch the RemoteException means i should use the getCause() method  in catch(Exception e) block;;
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16620832
if i write my own userdefined exception also same thing is happening
0
 
LVL 92

Expert Comment

by:objects
ID: 16620849
    catch(RemoteException e)
     {
          Throable cause = e.getCause();
           
     }
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16622109
Any kinds of exceptions thrown remotely will be wrapped up into remote exceptions and thrown by the container, I guess.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16628840
if i write my own checked exception then its working fine;;
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16629171
>> 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?
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 16629204
in my first post i have made a mistake now its working fine;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question