View Full Version : How to work with Exception?
asv
Nov 5th, 2004, 04:09 AM
I'm working with JDBC DAO objects and unchecked Spring Exception.
My code doesn't have try {..} catch (). Is it a good style?
All Spring exception are logging by LOG4j into log file. (I hope it works)
Code is more clear. But I cannot get a full stack trace and output it on error.jsp.
How are you working with Exceptions. Your opinion?
ojolly
Nov 5th, 2004, 04:41 AM
Using unchecked exception is good thing (c) when they mean that something fatal happened.
Checked exception are nice when they have a business meaning only.
As for handling exception with html gui, you can use the HandlerExceptionResolver interface to implement a piece of code which will be called when an exception is raised from your mvc code. This is an elegant way to centralise the behaviour of your application front to an unchecked exception.
to enable it, you simply have to define a bean of this type in the webApplicationContext and it gets registered automatically.
Hope it helps
Olivier
asv
Nov 5th, 2004, 05:00 AM
As for handling exception with html gui, you can use the HandlerExceptionResolver interface to implement a piece of code which will be called when an exception is raised from your mvc code. This is an elegant way to centralise the behaviour of your application front to an unchecked exception.
Olivier
Thanks. I didn't know about the HandlerExceptionResolver. But how will it work if I won't use Spring MVC?
I'm usinf JSF. For example:
public class MyBackingBean {
private MySpringService mySpringService
public String myAction() throws Exception {
mySpringService.runServiceOne(...);
}
}
Will all checked and uncheced exception into runServiceOne() handle by
HandlerExceptionResolver?
ojolly
Nov 5th, 2004, 05:15 AM
You're right, this behaviour is controlled by the spring MVC implementation itself.
I would check if the jsf mvc doesn't allow a kind of interceptor like in spring, or, if running in a servlet 2.3+ container, try the use of listener.
I used it successfully in a commercial project recently. You create a listener which you bind on your front servlet. In this listener, you simply execute
try {
chain.doFilter(request, response);
} catch (Exception e) {
// your exception handling code, including a redirection to a custom page with a RequestDispatcher e.g.
This way you have a framework agnostic exception handler...
Olivier
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.