aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJBException printing stacktrace even if handled in program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJBException printing stacktrace even if handled in program" Watch "EJBException printing stacktrace even if handled in program" New topic
Author

EJBException printing stacktrace even if handled in program

B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
Hi,
I have a simple Stateless bean with a method that persists an entity. There is a JSF bean client using this method. I have declared "throws EJBException" in the stateless EJB and I catch that exception in JSF managed bean(client). The problem is that even if I am catching the EJB exception in my JSF managed bean, the container still prints out stack trace. Here is the code for ejb and jsf managed bean.

Stateless ejb - StateManager


JSF managed bean - StateBean


In the above code, if a PersistenceException is raised it is wrapped in EJBException as per ejb specs. Although this does happen, I still get stack trace in my server log. Any idea why I get a stack trace in server log.

regards,
Nirvan.
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
declaring that your ejb can throws EJBException isn't considered wise as by default any enterprise Bean instance can throw this exception (as it extends RuntimeException) to it's container to report that the invoked business method or callback method could not be completed because of an unexpected error. however to answer your question ejb container intercepts any call to your beans, throwing EJBException indicates to the container as mentioned before there is unexpected problem may be database connection problem so the ejb container should log this error for the administrator to check as it is not business logic error. In the end you can control what is logged depending on the configuration of your application server.
B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82

declaring that your ejb can throws EJBException isn't considered wise as by default any enterprise Bean instance can throw this exception (as it extends RuntimeException) to it's container to report that the invoked business method or callback method could not be completed because of an unexpected error

Yes I should have thought this before. The throws clause is redundant.

however to answer your question ejb container intercepts any call to your beans, throwing EJBException indicates to the container as mentioned before there is unexpected problem may be database connection problem so the ejb container should log this error for the administrator to check as it is not business logic error. In the end you can control what is logged depending on the configuration of your application server

Yes, I think this exception is thrown under very exceptional conditions which would not occur during normal process. So it seems logical to print the trace.
Thanks for the explanation.

regards,
Nirvan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJBException printing stacktrace even if handled in program
 
Similar Threads
ejb create() Error java.lang. IllegalStateEx: Failed to find method for hash
please answer these sun j2ee test questions
J2EE Recommended Reading
unable to catch EJBException from ejbstore in facade
cannot retrieve stateless bean using JNDI