Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJBException printing stacktrace even if handled in program

 
B Nirvan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic