Page 1 of 2

Problems using error object

Posted: Mon Oct 02, 2017 8:50 am
by Cliff Wiernik
I have the following constructi:

bSaveErrorBlock := ErrorBlock( {|e| Break(e) } )

BEGIN SEQUENCE

DO WHILE !EOF()
SOME CODE
SKIP
ENDDO

RECOVER USING oError
WTF oError pause
wtf('Arguments: '+dc_xtoc(oError:arguments)) pause
wtf('Cargo: '+dc_xtoc(oError:arguments)) pause
wtf('Error description: '+dc_xtoc(oError:description)) pause
wtf('Gencode: '+dc_xtoc(oError:gencode)) pause
wtf('Operation: '+dc_xtoc(oError:operation)) pause
wtf('OSCode: '+dc_xtoc(oError:oscode)) pause

LB_Warning({'Arguments: '+dc_xtoc(oError:arguments), ;
'Cargo: '+dc_xtoc(oError:arguments), ;
'Error description: '+dc_xtoc(oError:description), ;
'Gencode: '+dc_xtoc(oError:gencode), ;
'Operation: '+dc_xtoc(oError:operation), ;
'OSCode: '+dc_xtoc(oError:oscode)}, ;
'Error Information')
lOK := .F.

ErrorBlock(bSaveErrorBlock)

END SEQUENCE

The WTF oError pause pauses and lets me browse the error object and I can see the instance variable.

However, when using WTF or LB_Warning (front-end to dc_msgbox()), it does not display anything. What do I need to do in order to display the error object attributes via a user popup or wtf.

Cliff

Re: Problems using error object

Posted: Mon Oct 02, 2017 9:10 am
by Cliff Wiernik
My error. the instance variable is args, not arguments.

Thus I generated an error inside my recover using statements.

Cliff

Re: Problems using error object

Posted: Mon Oct 02, 2017 9:49 am
by rdonnay
Thus I generated an error inside my recover using statements.
That was my first guess.

Re: Problems using error object

Posted: Mon Oct 02, 2017 10:31 am
by Cliff Wiernik
That was correct.

But I am having trouble with the call stack. It geneates the line of the lb_warning, then the line calling the function. How do I get the line causing the error, which is a few lines above the recover using. I just forced an assignment error to test. I see the error line in the regular temp.err log for normal handling but not withing my custom handler.

Re: Problems using error object

Posted: Mon Oct 02, 2017 10:53 am
by rdonnay
How do I get the line causing the error,
You have to walk through the stack in a for..next loop:

FOR i := 1 to 10
wtf Procname(i), ProcLine(i)
NEXT

Re: Problems using error object

Posted: Mon Oct 02, 2017 11:04 am
by Cliff Wiernik
That is what I am doing, but in the custom handler all I get it the line displaying the error object info as procline(0), then procline(1), is the calling function, but not the error line that caused the break(e) to be excecuted and then the RECOVER USING. How do I get the error line.

Re: Problems using error object

Posted: Mon Oct 02, 2017 11:09 am
by Cliff Wiernik
This is what I get. First line is the display of the error object. 2nd line is the line calling the function I am in, PRCOMMADEL(). The error line is not there.
errorline.jpg
errorline.jpg (31.78 KiB) Viewed 25051 times

Re: Problems using error object

Posted: Mon Oct 02, 2017 11:26 am
by rdonnay
Look at Alaska's errorsys.prg. It may help you.

Re: Problems using error object

Posted: Mon Oct 02, 2017 2:02 pm
by Cliff Wiernik
I did and tried using their code exactly. It appears that when you use a customer error object, it affects the stack. Must have to do something with the recover using, but the error object does not have a variable for the error line number. They check for a call stack method existing, but in the custom error handler, it does not exist.

Cliff

Re: Problems using error object

Posted: Mon Oct 02, 2017 3:10 pm
by rdonnay
I looked at different error handlers I have written over the years.

It looks like ProcName(2) and ProcLine(2) will tell you where the error occurred.