esak2000
asked on
foxpro error handling
I'm currently using the Microsoft.XMLHTTP object to access websites within my program (scan through a table with URLs).
The problem is that with my current error handler, which is a simple try/catch statement, ends when an error occurs. Is there a way with error handling to continue the code, or go to the next row of a scanned table when an error occurs, rather than ending the program?
The problem is that with my current error handler, which is a simple try/catch statement, ends when an error occurs. Is there a way with error handling to continue the code, or go to the next row of a scanned table when an error occurs, rather than ending the program?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just one follow up question, can I add a "loop" statement in the "catch"?
No, this is not allowed (it will generate error 2059) but you may set some variable and issue the LOOP based on this variable:
FOR i = 1 TO 5
TRY
llCatch = .F.
aa = bb
CATCH
? i
llCatch = .T.
ENDTRY
IF m.llCatch
LOOP
ENDIF
? "No LOOP"
NEXT
"No LOOP" should not appear.
ASKER
Perfect, thank you!
Well, to pull it together (though this already is solved):
If you do something like
There is no need to put a loop or the LOOP command for continuation of a loop into the try..catch, neither in the try, nor in the catch block. There also is no need for Pavels construct to set a variable llCatch, then. If you put try catch inside the loop you come out of it before the endscan and therefor loop and try with the next record again, this is what you intended, isn't it? Then simply do so :)
Edit: There is no wrong or right here, about where to put the try or the loop. It depends on your intention. If you want to continue trying further records, put the try inside the loop to continue with further records. If you want to stop processing data, when the first error happens, then put the loop inside the try..catch. Still you are free to do what you want :)
Bye, Olaf.
If you do something like
Try
Scan
oBrowser.navigate2(url)
Endscan
Catch
* ...
Endtry
Then the first error makes VFP leave the code in the try block and not return there. Try Catch is not meant for overall error handling, but for catching local errors, so the solution simply is to put it inside the loop.Scan
Try
oBrowser.navigate2(url)
Catch
* log url as temporary or permanently not working
Endtry
Endscan
There is no need to put a loop or the LOOP command for continuation of a loop into the try..catch, neither in the try, nor in the catch block. There also is no need for Pavels construct to set a variable llCatch, then. If you put try catch inside the loop you come out of it before the endscan and therefor loop and try with the next record again, this is what you intended, isn't it? Then simply do so :)
Edit: There is no wrong or right here, about where to put the try or the loop. It depends on your intention. If you want to continue trying further records, put the try inside the loop to continue with further records. If you want to stop processing data, when the first error happens, then put the loop inside the try..catch. Still you are free to do what you want :)
Bye, Olaf.
ASKER