1 Reply Latest reply on Apr 21, 2007 10:09 AM by Weston M. Price

    EJB 3.0 - Throwing Exceptions from Session Beans

    Sven Borkert Newbie

      Hello,

      I have a stateless Session Bean with a single test method that just throws an exception. I'm accessing the EJB via remote interface, but I'm always getting an exception on the client side that I don't understand:

      Exception: [Ljava.lang.StackTraceElement;
      java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement;
       at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
       ...
      


      The client is doing the following:

       try{
       InitialContext ic = new InitialContext();
       ExSessionRemote remote = (ExSessionRemote) ic.lookup("ExSessionBean/remote");
       remote.doit();
       }
       catch(Exception e){
       System.out.println("Exception: "+e.getMessage());
       e.printStackTrace();
       }
      


      The doit() method in the EJB:

       public void doit() throws Exception {
       throw new Exception();
       }
      


      The exception is defined in the remote interface as well:

      @Remote
      public interface ExSessionRemote {
       public void doit() throws Exception;
      }
      


      I tried throwing my own exception "TestException" (of course I defined this correctly in the method signatures and the interfaces). I tried TestException extending Exception and RemoteException, but whatever I do it always gives me the following exception on the client side:

      java.lang.reflect.UndeclaredThrowableException
       at $Proxy0.doit(Unknown Source)
       at applicationclient1.Main.main(Main.java:32)
      Caused by: java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement;
       at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      


      I just can't find anything about this with google.

      Regards,

      Sven