Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Catching error information
Message
From
27/06/2018 13:06:40
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01660874
Message ID:
01660914
Views:
59
>>>>>Hi,
>>>>>
>>>>>My app keeps log of all errors that a user would come across. I periodically checks this error log in order to "clean" up issues that users never report. Often times it is hard to figure what actually caused the error.
>>>>>
>>>>>Therefore, I decided to add 2 more pieces of information to the error log:
>>>>>1. Last key user pressed (lastkey())
>>>>>2. Where did he/she clicked with the mouse. And this one I don't know how to do. How can I "catch" (and would this really be helpful) where the user clicked right before the error occurred?
>>>>>
>>>>>TIA.
>>>>Dmitry,
>>>>
>>>>I fully agree with Cetin, f.y.i. I have in my Error.log
>>>>
>>>>
>>>>ASTK                                                     Local                             A             errorlogging
>>>>   (    1,    1)                                                                           N             1                                                        (              1,00000000)
>>>>   (    1,    2)                                                                           C             "d:\foxproprojects\zorgenzekerheid\classes\googlemailcomposer.vct"
>>>>   (    1,    3)                                                                           C             "frmgooglemail1.gglmailbox1.gglgrid1.column1.gglcntgrid1.lblname.click"
>>>>   (    1,    4)                                                                           C             "d:\foxproprojects\zorgenzekerheid\classes\googlemailcomposer.vct"
>>>>   (    1,    5)                                                                           N             1                                                        (              1,00000000)
>>>>   (    1,    6)                                                                           C             "this.Parent.doit()"
>>>>   (    2,    1)                                                                           N             2                                                        (              2,00000000)
>>>>   (    2,    2)                                                                           C             "d:\foxproprojects\zorgenzekerheid\classes\googlemailcomposer.vct"
>>>>   (    2,    3)                                                                           C             "frmgooglemail1.gglmailbox1.gglgrid1.column1.gglcntgrid1.doit"
>>>>   (    2,    4)                                                                           C             "d:\foxproprojects\zorgenzekerheid\classes\googlemailcomposer.vct"
>>>>   (    2,    5)                                                                           N             77                                                       (             77,00000000)
>>>>   (    2,    6)                                                                           C             "      .Left = m.lnLeft"
>>>>   (    3,    1)                                                                           N             3                                                        (              3,00000000)
>>>>   (    3,    2)                                                                           C             "d:\foxproprojects\zorgenzekerheid\progs\errorlogging.fxp"
>>>>   (    3,    3)                                                                           C             "ON... "
>>>>   (    3,    4)                                                                           C             "d:\foxproprojects\zorgenzekerheid\progs\errorlogging.prg"
>>>>   (    3,    5)                                                                           N             91                                                       (             91,00000000)
>>>>   (    3,    6)                                                                           C             "= Astackinfo(m.aStk)"
>>>>
>>>>
>>>>
>>>>which is produced by this code:
>>>>
>>>>
>>>>For i = Alen(m.aStk, 1) - 1 To 1 Step - 1
>>>>* I named each element to make it easier to understand (jjh)
>>>>	lcCurPrg  = m.aStk(m.i, 2)
>>>>	lcModule  = m.aStk(m.i, 3)
>>>>	lcSource  = m.aStk(m.i, 4)
>>>>	lcModLine = Transform(m.aStk(m.i, 5))
>>>>	lcSrcCode = m.aStk(m.i, 6)
>>>>
>>>>
>>>>Regards,
>>>>
>>>>Koen
>>>
>>>Maybe I missing something. But I don't see in your code above showing the Lastkey() or what user pressed that "caused" the error. Is it there but I don't see it?
>>
>>When you have the whole call stack, it tells you exactly what lines of code produced the error. You don't need the keystroke. I use a routine I call GetStack() that looks like this:
>>
>>
>>* Return the call stack as a string
>>
>>LOCAL lnStackSize, laCallStack[1], lcStackInfo, lnStackLevel
>>STORE 0 TO lnStackSize, laCallStack[1], lnStackLevel
>>STORE SPACE(0) TO lcStackInfo
>>* Use ASTACKINFO()
>>lnStackSize = ASTACKINFO(laCallStack)
>>FOR lnStackLevel = 1 TO m.lnStackSize
>>	lcStackInfo = m.lcStackInfo + ;
>>		"  Level: " + TRANSFORM(laCallStack[m.lnStackLevel, 1]) + CHR(13) + CHR(10) + ;
>>		"   File: " + laCallStack[m.lnStackLevel, 2] + CHR(13) + CHR(10) + ;
>>		"   Module/Object: " + laCallStack[m.lnStackLevel, 3] + CHR(13) + CHR(10)
>>	lcStackInfo = m.lcStackInfo + ;
>>		"   Line: " + TRANSFORM(laCallStack[m.lnStackLevel, 5]) + ;
>>		": " + laCallStack[m.lnStackLevel, 6] + CHR(13) + CHR(10)
>>ENDFOR lnStackLevel = 1 TO m.lnStackSize
>>
>>
>>RETURN m.lcStackInfo
>>
>>
>>By having it as a separate function, I can use it other debugging code. For example, when I don't understand why/where a particular property is changing, I'll add an assign method to the property and put code in it like:
>>
>>
>>DEBUGOUT PROGRAM()
>>DEBUGOUT "  New value =", m.tuNewValue
>>DEBUGOUT ""
>>DEBUGOUT "--- Call stack ---"
>>DEBUGOUT getstack()
>>DEBUGOUT "--- End call stack"
>>DEBUGOUT ""
>>
>>
>>Then, I can test and see every time the property gets changed, exactly what was going on.
>>
>>Tamar
>
>First, thank you very much for the code. But the line number only gets into the Stackinfo only if I include the code into the .exe. And I typically do not. Are you saying that you - when building your app - check Debug info in the project? I tried it once and it almost doubled the size of the .exe.

I'm rarely the one responsible for building EXEs, but when I am, I think Debug info is worth it.

>
>Also, regarding your approach of DEBUGOUT. I thought that DEBUGOUT only works when running the app from IDE, not when executing it as .EXE on customer system. Am I wrong about it?

No, that's for IDE debugging. I was just pointing out that the function is useful in lots of ways. You can also use it at runtime if you're logging something other than errors.

Tamar
Previous
Reply
Map
View

Click here to load this message in the networking platform