Alaska Software Inc. - Is there any way to replace WAA error handler?
Username: Password:
AuthorTopic: Is there any way to replace WAA error handler?
Marcin StryjekIs there any way to replace WAA error handler?
on Wed, 11 May 2005 10:24:54 +0200
Hi.
Is there any way to replace WAA error handler?. In out app we must handle 
errors by our custom
ERROR_SYS. Do you know any method how could I achevie this goal?

TIA
Marcin Stryjek
mstryjek@softar.com.pl
Phil Ide
Re: Is there any way to replace WAA error handler?
on Wed, 11 May 2005 10:10:39 +0100
Marcin,

> Is there any way to replace WAA error handler?. In out app we must handle 
> errors by our custom
> ERROR_SYS. Do you know any method how could I achevie this goal?

Yes, and you'll be glad to know that it is very easy.

In my apps, I install a temporary error handler as I enter a form-function,
and uninstall it as I leave.  That way, each form-function or package can
call it's own custom error handler.

I also only allow my custom error handler to do two things:

  1.  Dump callstack and error details to a log file
      This records the same details as you might get in an XPPERROR.LOG

  2.  Send the same details to me via email

After doing this, the custom error handler calls the default error handler,
so WAA will properly abort processing for the current form and send the
usual error page back to the client.

It is as simple as this:



   at beginning of your form function:
  local bErrBlk := ErrorBlock( {|o| MyErrorBlock(o) } )


   at the end of your form function
  ErrorBlock( bErrBlk )

To make this simpler, I save the default error block to a thread-safe
globally visible variable, create a pair of functions to handle setup/tidy
of the local environment and wrap all form-functions to call these:

Function STClaims( oHtml, oContext )
   if SessionBegin(oHtml,oContext)
      Claims(oHtml,oContext)
   endif
   SessionEnd(oHtml,oContext)
   return (TRUE)

Where "STClaims" is my WAA_FORM.  

SessionBegin() sets up the local environment (opens tables, validates user, 
sets paths, set error handler etc.).

SessionEnd() tidies the environment (closes tables, copies result page to
oHtml:put(), reset error handler etc.)

The actual code to handle the request is in Claims().

Note that the function ErrorBlock() install a GLOBAL error handler, so in
ractice you can't use a different error handler per thread, since you will
actually use the latest handler installed.

The way around this is to install an error-dispatcher as the default error
handler, and this should maintain an array of error handler code-blocks,
one for each thread.  When an error occurs, the error is sent to the
error-dispatcher which should then select the correct error-handler based
on the current threads ID, and pass the error through to that handler.

Regards,

Phil Ide

***************************************
* Xbase++ FAQ, Libraries and Sources: *
* goto: http://www.idep.org.uk/xbase  *
***************************************

That's not a bug. It's supposed to do that.
Marcin StryjekRe: Is there any way to replace WAA error handler?
on Wed, 11 May 2005 12:11:10 +0200
Hi again.
 It works!!!. Thank you VERY VERY much.
Marcin Stryjek
.
Phil Ide
Re: Is there any way to replace WAA error handler?
on Wed, 11 May 2005 14:18:26 +0100
Marcin,

> Hi again.
>  It works!!!. Thank you VERY VERY much.

See my site, I've added a new item (#81) for installing per-thread error
handlers.

Regards,

Phil Ide

***************************************
* Xbase++ FAQ, Libraries and Sources: *
* goto: http://www.idep.org.uk/xbase  *
***************************************

Commentator: An average potato