2 Replies Latest reply on Aug 29, 2002 10:27 AM by lepekhine

    UndeclaredThrowableException

    mohansaravanan

      <font size=3>

      Iam using jboss application server,my entity bean contain two primary keys,so i have used primary key class.i given my primary class below

      package payroll;

      import java.io.Serializable;
      public class PayrollPK implements java.io.Serializable{

      public String companyCode;
      public String yearNo;


      public PayrollPK(String companyCode,String yearNo){
      this.companyCode = companyCode;
      this.yearNo = yearNo;
      }

      public PayrollPK() {
      }


      public String toString() {
      return (companyCode.toString()+yearNo.toString());
      }



      public int hashCode()
      {
      return (companyCode.concat(yearNo)).hashCode();

      }


      public boolean equals(Object obj)
      {

      if (obj instanceof PayrollPK) {
      return (companyCode.equals(((PayrollPK)obj).companyCode) && yearNo.equals(((PayrollPK)obj).yearNo));
      }

      return false;

      }

      }


      if i am trying to link ejb using jsp,i am getting following error.
      UndeclaredThrowableException ,please any of one help me.

      with regards
      mohan

        • 1. Re: UndeclaredThrowableException
          lepekhine

          Hi, mohansaravanan!
          I think, your EJB method you call in jsp throws exception that is not declared in interface.
          Following is a qoute from java API srec:
          "Thrown by a method invocation on a proxy instance if its invocation handler's invoke method throws a checked exception (a Throwable that is not assignable to RuntimeException or Error) that is not assignable to any of the exception types declared in the throws clause of the method that was invoked on the proxy instance and dispatched to the invocation handler.

          An UndeclaredThrowableException instance contains the undeclared checked exception that was thrown by the invocation handler, and it can be retrieved with the getUndeclaredThrowable() method. UndeclaredThrowableException extends RuntimeException, so it is an unchecked exception that wraps a checked exception."

          • 2. Re: UndeclaredThrowableException
            lepekhine

            This is a common case when EJB method throws exception
            unexpected by client.
            Please, see java API description for UndeclaredThrowableException.
            May be it helps...
            With JBoss I often get exceptions with null message.
            Then I use somthing like:
            catch (Exception e) {
            String error_message = e.getMessage();
            if (error_message == null) {
            java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
            e.printStackTrace(new java.io.PrintStream(out)); // new PrintWriter(out) doesn't work here!
            error_message = out.toString();
            }
            e.printStackTrace();
            request.setAttribute("javax.servlet.jsp.jspException", new Exception(error_message));
            request.getRequestDispatcher(error_page).forward(request, response);
            }

            The idea is to throw Exception with a message that is
            an error stack trace.
            Regards, Alexander