Re: [HELP] How could I catch and process Errors in Struts + iBatis + DAO?

2005-03-24 Thread Pham Anh Tuan
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]


Re: [HELP] How could I catch and process Errors in Struts + iBatis + DAO?

2005-03-24 Thread Folashade Adeyosoye
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; iste.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]



Re: [HELP] How could I catch and process Errors in Struts + iBatis + DAO?

2005-03-24 Thread Rick Reumann
Folashade Adeyosoye wrote the following on 3/24/2005 10:59 AM:
Agood way that i have found out was to define a  BaseExceptionHandler.java class
Yes my Struts apps have this also. Actually I no longer catch any 
Exceptions in my Actions and let this Base class handle it all. Makes 
your Actions much cleaner in my opinion.

So in my struts-config I have something like:
global-exceptions
	exception handler=com.foo.bar.AppExceptionHandler 
key=error.general path=/WEB-INF/jsp/exception.jsp 
type=java.lang.Exception/
/global-exceptions

Any exceptions that make it to the Action will propogate to the above 
handler. Then you can do additional logging and forward to a nicer error 
display page.

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


Re: [HELP] How could I catch and process Errors in Struts + iBatis + DAO?

2005-03-24 Thread Rick Reumann
Yuniar Setiawan wrote the following on 3/23/2005 6:57 AM:
There is a good example at
http://www.reumann.net/struts/ibatisLesson1.do about this. download
the sample war and look inside.
Actually as Leon pointed out to me, my example isn't that good for 
Exception handling. (Sorry I wrote it fast and was lazy:)

Do NOT follow that example as a 'best practices' for Exception handling 
- it's anyting but good for that. (The example is more for a demo of 
using the basics of a struts-iBATIS-Dao integration - but I definitely 
cut corners in places).

One example is in the Action, even though I use a service class (which 
really is a facade if I have my design pattern names correct), I don't 
catch a ServiceException in my Action but instead I catch a 
DAOException. I think it best to insulate yourself in the Action from 
anything related to the DAO and instead just catch some 
ServiceException(maybe call it DataAcessFacade vs service would be 
better also).

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


[HELP] How could I catch and process Errors in Struts + iBatis + DAO?

2005-03-23 Thread Pham Anh Tuan
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

Re: [HELP] How could I catch and process Errors in Struts + iBatis + DAO?

2005-03-23 Thread Yuniar Setiawan
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]