You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian McGovern <bm...@imediainc.com> on 2005/02/15 16:28:27 UTC
Proper n tiered exception handling
I'm looking to get a handle on best exception handling practices in my app. Kinda beginner question i guess, sorry.
Im catching the various sql and naming exceptions in the data classes and logging and throwing a custom exception called ApplicationException which is blank and provided below. I've read up but an still a little confused on how exactly to build this exception class to extend the available struts exception classes that would gracefully map to an error display jsp where i could display the error to the user. Right now I just get the HTTP status 500 strack trace on the screen.
Controller snippet that catches the data obj's thrown ApplicationException:
------------------------------------------------------------------------
try {
zRepBeanBn = MyData.getRepByID(StringUtils.convertToInt(request.getParameter("RepID")));
}catch (ApplicationException zAppEx){
throw zAppEx;
}
------------------------------------------------------------------------
ApplicationException that needs work: How do I extend this?
------------------------------------------------------------------------
public class ApplicationException extends Exception {
public ApplicationException(String message) { }
}
------------------------------------------------------------------------
Thanks
RE: Proper n tiered exception handling
Posted by Mark Bennett <ma...@ncmail.net>.
I think you are missing out on some usefull features by using this. You
can't use the ActionMapping Parameter property to distinguish operations
<action ... parameter="add" ... /> and you will have to reimplement a
solution if you use DispatchAction. I think there are benefits to
declaritive exception handling, flexibility.
Mark
-----Original Message-----
From: Ole Hildebrandt [mailto:OH@BWSolution.de]
Sent: Tuesday, February 15, 2005 12:21 PM
To: 'Struts Users Mailing List'
Subject: AW: Proper n tiered exception handling
Hi.
My personal opinion is, that the Struts Exception handling doesn't bring any
benefits.
I use an approch based on inheritance and the "Template Method"-Pattern from
the GoF:
I create an abstract Class extended from "Action". All application-Specific
Actions extend that class. The Abstract Action-class is responsible for
catching all Exceptions that were not explicitly catched by the extending
class.
Source-Snippet from the Abstact Class "AbstractContoller.java":
public abstract class AbstractController extends Action {
//Template-Method. Calls "doExecute" on each Request and handles
uncaught Exceptions:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try {
return doExecute(mapping,form, request,response);
} catch (Throwable e) {
request.setAttribute("messagekey","error.unknownError");
log.error("Uncought Exception",e);
return mapping.findForward("error");
}
}
//All extending classed implement this method
public abstract ActionForward doExecute(ActionMapping mapping, ActionForm
form,
HttpServletRequest request, HttpServletResponse response) throws
Exception ;
And I use ExceptionChaining. See this article for more info:
http://www.javaworld.com/javaworld/jw-09-2001/jw-0914-exceptions.html?
Kind Regards
Ole
-----Ursprüngliche Nachricht-----
Von: Brian McGovern [mailto:bmcgovern@imediainc.com]
Gesendet: Dienstag, 15. Februar 2005 16:28
An: user@struts.apache.org
Betreff: Proper n tiered exception handling
I'm looking to get a handle on best exception handling practices in my app.
Kinda beginner question i guess, sorry.
Im catching the various sql and naming exceptions in the data classes and
logging and throwing a custom exception called ApplicationException which is
blank and provided below. I've read up but an still a little confused on
how exactly to build this exception class to extend the available struts
exception classes that would gracefully map to an error display jsp where i
could display the error to the user. Right now I just get the HTTP status
500 strack trace on the screen.
Controller snippet that catches the data obj's thrown ApplicationException:
------------------------------------------------------------------------
try {
zRepBeanBn =
MyData.getRepByID(StringUtils.convertToInt(request.getParameter("RepID")));
}catch (ApplicationException zAppEx){
throw zAppEx;
}
------------------------------------------------------------------------
ApplicationException that needs work: How do I extend this?
------------------------------------------------------------------------
public class ApplicationException extends Exception {
public ApplicationException(String message) { } }
------------------------------------------------------------------------
Thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
AW: Proper n tiered exception handling
Posted by Ole Hildebrandt <OH...@BWSolution.de>.
Hi.
My personal opinion is, that the Struts Exception handling doesn't bring any
benefits.
I use an approch based on inheritance and the "Template Method"-Pattern from
the GoF:
I create an abstract Class extended from "Action". All application-Specific
Actions extend that class. The Abstract Action-class is responsible for
catching all Exceptions that were not explicitly catched by the extending
class.
Source-Snippet from the Abstact Class "AbstractContoller.java":
public abstract class AbstractController extends Action {
//Template-Method. Calls "doExecute" on each Request and handles
uncaught Exceptions:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try {
return doExecute(mapping,form, request,response);
} catch (Throwable e) {
request.setAttribute("messagekey","error.unknownError");
log.error("Uncought Exception",e);
return mapping.findForward("error");
}
}
//All extending classed implement this method
public abstract ActionForward doExecute(ActionMapping mapping, ActionForm
form,
HttpServletRequest request, HttpServletResponse response) throws
Exception ;
And I use ExceptionChaining. See this article for more info:
http://www.javaworld.com/javaworld/jw-09-2001/jw-0914-exceptions.html?
Kind Regards
Ole
-----Ursprüngliche Nachricht-----
Von: Brian McGovern [mailto:bmcgovern@imediainc.com]
Gesendet: Dienstag, 15. Februar 2005 16:28
An: user@struts.apache.org
Betreff: Proper n tiered exception handling
I'm looking to get a handle on best exception handling practices in my app.
Kinda beginner question i guess, sorry.
Im catching the various sql and naming exceptions in the data classes and
logging and throwing a custom exception called ApplicationException which is
blank and provided below. I've read up but an still a little confused on
how exactly to build this exception class to extend the available struts
exception classes that would gracefully map to an error display jsp where i
could display the error to the user. Right now I just get the HTTP status
500 strack trace on the screen.
Controller snippet that catches the data obj's thrown ApplicationException:
------------------------------------------------------------------------
try {
zRepBeanBn =
MyData.getRepByID(StringUtils.convertToInt(request.getParameter("RepID")));
}catch (ApplicationException zAppEx){
throw zAppEx;
}
------------------------------------------------------------------------
ApplicationException that needs work: How do I extend this?
------------------------------------------------------------------------
public class ApplicationException extends Exception {
public ApplicationException(String message) { } }
------------------------------------------------------------------------
Thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org