Page 1 of 1

FWErrorsys()

PostPosted: Wed Apr 03, 2024 3:50 pm
by Natter
How the FWErrorsys() function works ?

Re: FWErrorsys()

PostPosted: Wed Apr 03, 2024 7:54 pm
by Antonio Linares
FWH procedure FWErrorSys() is identical to FWH procedure ErrorSys() that it is automatically called by Harbour.

procedure ErrorSys() invokes function ErrorBlock() to replace the default application errorBlock:

ErrorBlock( { | e | ErrorDialog( e ) } )

Re: FWErrorsys()

PostPosted: Wed Apr 03, 2024 8:26 pm
by Natter
I wrote the FW Error Sys() function in which I specified my code block

Error Block( { | e | MyFunc(), Error Dialog( e ) } )
However, when compiling, I get an error - the Error Dialog() function was not found

Re: FWErrorsys()

PostPosted: Wed Apr 03, 2024 9:06 pm
by Antonio Linares
function ErrorDialog( e ) is static so you have to modify errsysw.prg to make it public or entirely replace FWH errsysw.prg with one of your own

Re: FWErrorsys()

PostPosted: Wed Apr 03, 2024 11:16 pm
by nageswaragunupudi
You wrote:
Code: Select all  Expand view
Error Block( { | e | MyFunc(), Error Dialog( e ) } )


From this, I understand that when an error occurs, you want MyFunc() should be executed first and then invoke the FWH ErrorDialog.

We can achieve this without modifying errsysw.prg
Please try this sample:
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local bFwErr

   bFwErr   := ErrorBlock()
   ErrorBlock( { |e| MyFunc( e ), Eval( bFWErr, e ) } )

   ? "Will now generate Error and see"
   ? Date() == 9

return nil

function MyFunc( e )

   MsgInfo( e:Description + CRLF + e:Operation, "MY FUNC" )
   ? "Next, you will see FWH Error Dialog"

return nil


Please just run the sample and see how your MyFunc() is exeucted first and later FWH's ErrorDialog() is executed.

Re: FWErrorsys()

PostPosted: Wed Apr 03, 2024 11:37 pm
by nageswaragunupudi
In case, we want to take some action after the FWH's ErrorDialog() is executed, we can do like this:

Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   SetPostErrorAction( { |cLogFile, e| MyFunc( cLogFile, e ) } )

   ? "Will now generate Error and see"
   ? Date() == 9

return nil

function MyFunc( cLogFile, e )

   ? "Sending email " + TrueName( cLogFile )

return nil

Re: FWErrorsys()

PostPosted: Thu Apr 04, 2024 12:01 am
by nageswaragunupudi
In case we do not like FWH provided ErrorDialog and like to display our own ErrorDialog, we can do this:
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   SetErrorDialog( { |e, aStack, cErrLogText, cErrLogFile | ;
       MyErrorDialog( e, aStack, cErrLogText, cErrLogFile ) } )

   ? "Will now generate Error and see"
   ? Date() == 9

return nil

function MyErrorDialog( e, aStack, cErrLogText, cErrLogFile )

   MsgInfo( e:Description + CRLF + e:Operation + CRLF + ;
      FW_ArrayAsList( e:Args, ", " ) + CRLF + ;
      FW_ArrayAsList( aStack, CRLF ), ;
      "MY ERROR DIALOG" )

return nil


Please run the above three programs as it is and see.
We can do all the aboe without modifying the errsysw.prg

Re: FWErrorsys()

PostPosted: Thu Apr 04, 2024 3:49 am
by nageswaragunupudi
Lastly,
If we do not like to use FWH's error handling and like to have our own error handler

Then at the beginning of the application, execute
Code: Select all  Expand view
ErrorBlock( { |e| MyErrorHandler( e ) } )


and have our own error handling module like "errsysmy.prg" with this function.

Re: FWErrorsys()

PostPosted: Thu Apr 04, 2024 8:52 am
by Natter
From this, I understand that when an error occurs, you want MyFunc() should be executed first and then invoke the FWH ErrorDialog.


Yes, that's exactly what I wanted. Thank you, Rao !