Agood way that i have found out was to define a  BaseExceptionHandler.java class

< snip > 
public final class BaseExceptionHandler extends ExceptionHandler {

     public ActionForward execute(Exception ex, ExceptionConfig ae,
                                 ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
    throws ServletException {
                 ActionErrors errors =  (ActionErrors)
request.getAttribute(Globals.ERROR_KEY);

        if (errors != null) {
            return null;
        }

        ActionForward forward =
            super.execute(ex, ae, mapping, form, request, response);

       // get user that is logged in from session
       // create a timestamp (String)
       
      StackTraceElement[] ste = ex.getStackTrace();
      StringBuffer sbStackTrace = new StringBuffer();
      for (int i = 0; i<ste.length; i++) {
        sbStackTrace.append(ste[i].toString());
        sbStackTrace.append("\n");
      }

      //  create a unique error code from   userName_Timestamp

      // Save the error code in the session
      if ( session != null ){
        session.setAttribute("errorId", sb.toString());
      }      

      //return new ActionForward(ae.getPath());
      return forward;
   }  // end execute

}

< / snip > 


Now in your  struts-config.xml have this in there

 <global-exceptions>
  <exception key="errors.technical.difficulty"
path="/jsp/systemError.jsp" type="java.lang.Exception"
handler="com.path.to.my.class.BaseExceptionHandler"/>
 </global-exceptions>


and aboviously "errors.technical.difficulty" would be in the resource
properties file, waht ever message you want to display

Now in the systemError.jsp, display the errorId....


This is a catch all error, design pattern......

When a user reports a error ask for the error Code on the screen and
then you check your log4J file for that error code to debug.


hope that helps :)

On Thu, 24 Mar 2005 15:04:05 +0700, Pham Anh Tuan <[EMAIL PROTECTED]> wrote:
> thank you very much, Yuniar :")
> 
> ----- Original Message -----
> From: "Yuniar Setiawan" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <user@struts.apache.org>
> Sent: Wednesday, March 23, 2005 6:57 PM
> Subject: Re: [HELP] How could I catch and process Errors in Struts + iBatis
> + DAO?
> 
> > There is a good example at
> > http://www.reumann.net/struts/ibatisLesson1.do about this. download
> > the sample war and look inside.
> >
> > cheers
> >
> >
> > On Wed, 23 Mar 2005 17:31:53 +0700, Pham Anh Tuan <[EMAIL PROTECTED]>
> > wrote:
> >> Hi,
> >>
> >> I don't know how to catch and process errors in Struts + iBatis + DAO.
> >>
> >> Anyone here can help me, plz :(
> >>
> >> thank for ur reading.
> >>
> >> Tuan
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to