I had not considered doing that before so thanks for the input, it would be better. Sorry to the OP for partially hijacking his thread.
Andy Hahn wrote: > > > Yes you are chaining, but if you write to a database, for example, the > user could refresh the page and re-write to the database. The point I was > trying to make was to use the PRG pattern. > > > > >> Date: Mon, 19 Jan 2009 03:27:57 -0800 >> From: ga...@prodia.co.uk >> To: user@struts.apache.org >> Subject: RE: exception handling >> >> >> I must be misunderstanding something, is that not what I am already doing >> my >> chaining to another action? >> >> >> >> Andy Hahn wrote: >> > >> > Regarding to the first responder - you could take this a step further >> and >> > have ActionUnhandledExceptionHandler redirect to another action >> (Redirect >> > After Post). >> > >> > >> > >> > >> >> Date: Sun, 18 Jan 2009 06:24:24 -0800 >> >> From: ga...@prodia.co.uk >> >> To: user@struts.apache.org >> >> Subject: Re: exception handling >> >> >> >> >> >> I know this is slightly different from the way you are trying it but >> this >> >> is >> >> the way I am currently doing it is: >> >> >> >> <global-exception-mappings> >> >> <exception-mapping exception="java.lang.Exception" >> >> result="unhandledExceptionHandler"/> >> >> </global-exception-mappings> >> >> >> >> >> >> <global-results> >> >> <result name="unhandledExceptionHandler" type="chain"> >> >> <param >> >> name="actionName">actionUnhandledExceptionHandler</param> >> >> <param >> name="namespace">/unsecured</param> >> >> </result> >> >> <global-results> >> >> >> >> >> >> and then I define an action - actionUnhandledExceptionHandler: >> >> >> >> public class ActionUnhandledExceptionHandler extends BaseActionSupport >> { >> >> >> >> private Exception exception; >> >> >> >> @Override() >> >> public String execute() { >> >> >> >> if(exception != null){ >> >> logException(serviceProsocUser , exception); >> >> >> >> // Send the user to the error page with a message >> >> addActionError(getText("common.unknown.exception") + "<div >> >> class=\"errorMessageExceptionText\">" + exception.toString() + >> "</div>"); >> >> >> >> return ERROR; >> >> >> >> } else { >> >> logger.error("***** TRIED TO LOG EXCEPTION BUT EXCEPTION >> WAS >> >> NULL! I HAVE NOT LOGGED THIS EXCEPTION! *****"); >> >> } >> >> >> >> >> >> >> addActionError(getText("actionUnhandledExceptionHandler.could.not.log.exception")); >> >> return "canNotLogDatabaseError"; >> >> } >> >> >> >> public void setException(Exception exception) { >> >> this.exception = exception; >> >> } >> >> } >> >> >> >> >> >> The logException method calls this to get the actual stacktrace: >> >> >> >> public String exceptionStackTraceToString(Exception exception){ >> >> >> >> StringWriter stringWriter = new StringWriter(); >> >> exception.printStackTrace(new PrintWriter(stringWriter)); >> >> String stackTrace = stringWriter.toString(); >> >> >> >> // As stackTrace may contain regular expression special >> >> characters >> >> we need to make them harmless first >> >> return Matcher.quoteReplacement(stackTrace); >> >> } >> >> >> >> I then, from within logException, write the exception to an email and >> the >> >> database but you can of course do what you like with it. >> >> >> >> HTH >> >> >> >> >> >> >> >> JJ__ wrote: >> >> > >> >> > Hello, >> >> > I am trying to implement declarative exception handling for all the >> >> > possible exceptions. The problem is that in this way I only catch >> some >> >> > exceptions (not all of them) and I cant get its stack trace nor its >> >> > message(it is only rendered the rest of my JSP but not the >> information >> >> > about the stack or message about the excepion). I have this: >> >> > >> >> > In my struts.xml >> >> > <global-results> >> >> > <result name="handleException" >> >> > type="redirect">error.jsp</result> >> >> > </global-results> >> >> > >> >> > <global-exception-mappings> >> >> > <exception-mapping result="handleException" >> >> > exception="java.lang.Exception"/> >> >> > </global-exception-mappings> >> >> > >> >> > And in my JSP >> >> > <%@ taglib prefix="s" uri="/struts-tags" %> >> >> > ... >> >> > <s:property value="%{exception.message}"/> >> >> > <s:property value="%{exceptionStack}"/> >> >> > >> >> > Thanks in advanced >> >> > >> >> > >> >> > >> >> > >> >> > >> >> >> >> -- >> >> View this message in context: >> >> http://www.nabble.com/exception-handling-tp21518870p21528352.html >> >> Sent from the Struts - User mailing list archive at Nabble.com. >> >> >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >> >> For additional commands, e-mail: user-h...@struts.apache.org >> >> >> > >> > _________________________________________________________________ >> > Windows Live™ Hotmail®: Chat. Store. Share. Do more with mail. >> > >> http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t1_hm_justgotbetter_howitworks_012009 >> > >> >> -- >> View this message in context: >> http://www.nabble.com/exception-handling-tp21518870p21541248.html >> Sent from the Struts - User mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >> For additional commands, e-mail: user-h...@struts.apache.org >> > > _________________________________________________________________ > Windows Live™: Keep your life in sync. > http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009 > -- View this message in context: http://www.nabble.com/exception-handling-tp21518870p21547741.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org