8 Replies Latest reply on Nov 1, 2001 2:07 AM by banigreyling

    UndeclaredThrowableException when setting value on remote in

    banigreyling

      Hi,

      I explicitly instructed my database to throw an exception if a specific column is updated, because I want to know which exception I must handle. I have a try/catch block in a session bean from where I call the setMethod on a CMP bean that throws the exception. I just get an UndeclaredThrowableException on the client side, which aint very nice. I cannot even catch the exception in the session bean when I catch Throwable. It seems that the container loose it if an ejbStore fails.

      How am I supposed to handle database exceptions when I call methods on my remote interfaces?

      Configuration: Jboss 2.2.2
      Platform: Win NT4
      Database: SQLServer 2000
      JDBC Driver: www.j-netdirect.com's JSQLConnect

        • 1. Re: UndeclaredThrowableException when setting value on remot
          lisa_r

          Hi BANIGREYLING,
          I have the exact same problem that you have/had. If you see this can you please tell me how you solved it.

          Thanks!!!!

          /Lisa

          • 2. Re: UndeclaredThrowableException when setting value on remot
            glote

            This happens because the container tries to invoke the method, but get a checked exception that the that's not declared in the method you're calling. If you declare the method in the remote interface of the entitybean as throws SomeException the UndeclaredThrowableException should go away.

            BTW you can get the exception that caused UndeclaredThrowableException to be thrown by calling the getUndeclaredThrowableException method on the UndeclaredThrowableException

            See the javadoc for more info on UndeclaredThrowable:
            http://java.sun.com/j2se/1.3/docs/api/index.html

            • 3. Re: UndeclaredThrowableException when setting value on remot
              glote
              • 4. Re: UndeclaredThrowableException when setting value on remot
                lisa_r

                Hi glote,
                Thanks for your reply!

                EJB is very new to me so I am not sure that I understand what you mean. In which method sould I declare an extra Exception?

                I call a set method in my entity bean which only do the following:

                public void setSystemLanguage(String systemLang)
                {
                this.systemLang = systemLang;
                }

                In the remoteinterface the method is declared like this:
                public void setSystemLanguage( String systemLang )
                throws RemoteException;

                When I for instance try to set a value that has to many characters to fit into the databasefield the ejbStore method throws an EJBexception that wraps a SQLException. The client only gets an UndeclaredThrowableException.

                Thanks!

                /Lisa

                • 5. Re: UndeclaredThrowableException when setting value on remot
                  banigreyling

                  Hi,

                  Thanks for the reply. The UndeclaredThrowableException originates from the proxy instance on the client side, because the error thrown by the container is not a subclass of the RemoteException (which is the onlydeclared exception on the remote interface). According to section 12.3.1 of the EJB1.1 Spec, the container should throw RemoteException in the case when an Exception other than an AppException occured in the implementation.

                  To put it differently. If I do not declare any exceptions in my EntityBean subclass, I should not get an UndeclaredThrowableException on the client side, but rather a RemoteException. To put it frankly, I think it is a bug in JBoss. The container is not throwing a RemoteException as it is required to do.

                  • 6. Re: UndeclaredThrowableException when setting value on remot
                    banigreyling

                    To be more exact:

                    case1: Bean Participating in existing transaction
                    When an exception occurs in the container which is not thrown by the EnityBean subclass (i.e. your cmp bean) the container should throw javax.transaction.TransactionRolledBackException (which extends java.rmi.RemoteException), and not javax.transaction.RollbackException as it is currently doing. If javax.transaction.TransactionRolledBackException is thrown, you will 1) Not get UndeclaredThrowableException ,2) Be able to check the root exception (e.g. SQLException) on the client and try to recover from it.

                    case2: Bean Creating new transaction
                    When an exception occurs in the container which is not thrown by the EnityBean subclass (i.e. your cmp bean) the container should throw java.rmi.RemoteException.

                    With javax.transaction.TransactionRolledBackException you will alse be able to check the root exception, which was an issue on another forum thread.

                    But then again, maybe I am just a bad spec reader:)

                    • 7. Re: UndeclaredThrowableException when setting value on remot
                      lisa_r

                      Hi BANIGREYLING,
                      Thanks for your reply! :)
                      I use bmp and JBoss 2.2.2. What can I do so that I don´t get UndeclaredThrowableException?

                      • 8. Re: UndeclaredThrowableException when setting value on remot
                        banigreyling

                        I would think a feasable (and temporary!) workaround will be to add javax.transaction.RollbackException to the throws clause of all the set methods on your Remote Interfaces. This will allow the incorrect (IMHO) exception thrown by the container to be propagated to the client. Note however that this is not an elegant solution.

                        PS I would appreciate it if one of the lead developers can comment on my postings in this thread, as I think it may result in a bugfix. Or can someone tell me I am wrong and why!?