VFP debugger is very powerful. It allows us to debug our code using breakpoint. There are four types of breakpoint supported:

  1. Break at location
  2. Break at location if expression is true
  3. Break when expression if true
  4. Break when expression has changed

I am not going to explain each of them. Instead, I would like to share my favourite breakpoint expresions during testing.

Break if error occurred

Most of the time, I have error handler in our application that using ON ERROR command. Especially, if my application is built on top of framework. Error handler will take over if error occurred. It responsibles to log error into error log, show "friendly" error message, or shutdown/restart the application and back to VFP IDE.

Sometime, I feel it is not so "friendly" to me because I can't debug immediately when error occurred (unless I can turn off the error handling during development, but some frameworks just can't turn error handling off). Therefore, I got to go thru couple of steps in order to "start" debugging.

Firstly, I got check error log to get actual error message and line number, open up the scx/vcx/prg, go to the line of code that hit error, visualize and analyze the code based on error message given. If I able to find the mistakes, fix it, otherwise set breakpoint, re-run the application and steps to reproduce. Application breaks when VFP reach to breakpoint, then we check for any mistakes, what is the value of the desired variables, what is the return value and etc. (Is it the way you debug?)

To avoid the steps as mentioned above, I always like to add the following breakpoint expression in debugger:

Break when expression is true - Error() > 0

This will cause VFP to break if any error occurred but before our error handler take over. Then, I can step into error handler code. Skip error handling code by jump to last line of code using "Set Next Statement" (for example to RETURN statement) and back to program that hit error and start checking for mistakes. You may ask why not set breakpoint at the first line of error handler. Yes, it should work but I lazy to open up the prg. :P Beside, I have projects built on top of different frameworks. Then I got to remember to set breakpoint to each of them when swicthing project..

 

Break if current program is ...

Most of the time, the code that hit error is not the cause of error. It is true especially that is logical error. In this case, I need to trace from the beginning of the code in that particular method/function. I set breakpoint expression as below so that VFP will break once it reach the specified method/function:

Break when expression is true - "MYCLASS.MYMETHOD" $ PROGRAM()

 

Do you have any tips to share?

 

Technorati tags: , ,