3 Replies Latest reply on Sep 6, 2005 5:04 AM by Henrik Johansson

    Unable to catch application exceptions

    Henrik Johansson Newbie

      I am using JBoss 4.0.3RC1 with EJB3.0 Beta 1.

      I have a number of self-declared exception classes for my application, every class extending java.lang.Exception. EJB session bean business methods (and their interfaces) declare these exceptions in the throws clause as needed.

      The problem is that I am unable to catch these application exceptions in the web tier. Instead I always end up catching the java.lang.Exception class though with the cause being correct (for example AxsDuplicateUsernameException). How come?

      The exception constructor:

      public AxsDuplicateUsernameException()
       {
       super("The username already exists in the system.");
       }
      


      The throw phase:
       // 2. Check so that the username is available and not used.
       if((em.find(Subscriber.class, subscriber.getUsername()) != null))
       throw new AxsDuplicateUsernameException();
      

      This is an excerpt from my client JSF bean class.

      ...
       try
       {
       RegisterLocal registerBean = (RegisterLocal)ServiceLocator.getInstance()
       .getEJB(ServiceLocator.getInstance().REGISTER_CLASS);
       this.person = registerBean.checkPerson(this.person, this.subscriber, this.getPassword2());
       return RegisterPersonBean.VALID_PERSON_REGISTER_DATA_OUTCOME;
       }
       catch(AxsDuplicateUsernameException ex)
       {
       // Never executes
       MessageHelper.addError("error.username.duplicate", null);
       return RegisterPersonBean.INVALID_PERSON_REGISTER_DATA_OUTCOME;
       }
       catch(Exception ex)
       {
       // Executes
       MessageHelper.addFatal("fatal.unknown", null);
       return RegisterPersonBean.INVALID_PERSON_REGISTER_DATA_OUTCOME;
       }
      ...


      The necessary classes are packaged correctly and available for both business and web tier.

      Anyone have an idea? Thanks in advance.

      /Henrik