2 Replies Latest reply on Mar 1, 2006 5:22 AM by Martin Ganserer

    Exception handling

    Martin Ganserer Novice

      Hello,

      I am currently using EJB3 RC3 and I have some problems with exceptions.
      If my DAO throws a new Exception a remote client that should take care of that exception ignores it. Ignoring means that the programm does not go right into the catch clause.

      Here is an example:

      
      public Forecast getForecastByDate(int month,int year) throws GenericBusinessException
       {
       StringBuffer ejbQL = new StringBuffer();
      
       try
       {
       ejbQL.append("select f from Forecast f ");
       ejbQL.append("where f.month = :paramMonth ");
       ejbQL.append("and f.year = :paramYear ");
      
       Query query = em.createQuery(ejbQL.toString());
      
       query.setParameter("paramMonth",month);
       query.setParameter("paramYear",year);
      
       return (Forecast) query.getSingleResult();
       }
       catch (RuntimeException e)
       {
       logService.logError
       (
       this.getClass().getName(),
       Thread.currentThread().getStackTrace(),
       e.getMessage()
       );
       throw new GenericBusinessException(e.getMessage(), e.getCause());
       }
       }


      My client looks like this:

       try
       {
       forecast = forecastManager.getForecastByDate(cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR));
       }
       catch (GenericBusinessException e1)
       {
      
       System.out.println("Exception should be handled here!");
       }
      


      Did I something wrong or should I migrate to RC5 PFD?

      Thanks a lot!

        • 1. Re: Exception handling
          aidan davis Newbie

          Could be a class def problem.....make sure GenericBusinessException is in the clients class path at run time (i.e it should be a common component used by both client and service - e.g. in the root of the ear linked by manifest).

          Simple suggestion I know but I can't see anything explicitly wrong with your code.

          • 2. Re: Exception handling
            Martin Ganserer Novice

            Hi,

            I made a small test to check if the Exception class is known in the client.
            I simply fired a GenericBusinessException in the client without any problem!

             try
             {
             throw new GenericBusinessException();
             //user3 = userManager.getUserByName("ganserder");
             }
             catch (GenericBusinessException e)
             {
             System.out.println("Exception");
             }


            If the remote method throws the same exception it does not work!
            What should I do?