Discussions

EJB programming & troubleshooting: Exceptions between ejb and web

  1. Exceptions between ejb and web (4 messages)

    Hi,

    I am abit puzzle at this and any insight will be appriciated. I have a session bean where in a method signiture it thows a custom exception call "UserNotFoundException". The exception is exposed to the remote interface.

    In my web teir I have use reflection to discover this bean and ionvokes its appropriate method.

    All well and good but why is it when I through the "UserNotFoundException" in my session bean I get a stack trace in my log even though it is being caught by "InvocationTargetException" in my reflection proceedures??

    I am using the ejb's remote interface if thats a reason for it...

    Thanks for any insight..
    Charlie
  2. Because u are using reflection[ Go to top ]

    Because u are using reflection - u are getting the InvokationTargetException. It will have the user exception wrapped internally. The getCause() and the getTargetException() methods can be used to get the real exception the session bean has thrown.
  3. Maybe I miss understood your answer. I can get the cause from the exception thrown by InvokationTargetException.

    What I don't understand is that why my session ejb is still printing a stack trace even tho the exception was caught.

    For example (in te POJO world). I have 2 classes A and B. Class B is written like this:
    public class B{
     public void someMeth throws Exception(){
        throw new Excpetion();
     }
    }

    If class A calls B.someMeth() and surronds the B.someMeth() with a try/catch loop no stack trace will be printed (unless I code it to print the exception)

    Now in my question is that Class B is the session bean and when my servlet (i.e. class A) calls my session bean (using reflection the ejb contanier prints the exception even tho it is caught by InvokationTargetException.
  4. Exceptions between ejb and web[ Go to top ]

    Hi,
       Well the application exceptions won't be logged. Its only the system exceptions that get logged. Can you try wrapping your exception in EJBException and then throwing it. I think that its because of the RemoteException (which is a checked exception but is considered as system exception) that its getting logged.

    Cheers.

    Sawan
  5. Just a correction in my previous post .

    "Can you try wrapping your exception in EJBException and then throwing it".This will get logged


    sawan