Solved

foxpro error handling

Posted on 2013-11-12
6
600 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:esak2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 39643855
Well...  TRY CATCH continues the code execution after the ENDTRY command so if you enclose a smaller part of code into TRY-CATCH then you may achieve what you need.

Another option is to use Error event in your class. If you define Error event then it is fired when an error occurs and then the control returns to the next line of your code.

And finally ON ERROR also offers the option to continue. RETURN command in your error procedure continues after the line which caused the error.
0
 

Author Closing Comment

by:esak2000
ID: 39643856
Thank you for the super quick response. Exactly what I needed.
0
 

Author Comment

by:esak2000
ID: 39643858
Just one follow up question, can I add a "loop" statement in the "catch"?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 42

Expert Comment

by:pcelba
ID: 39643908
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

Open in new window

"No LOOP" should not appear.
0
 

Author Comment

by:esak2000
ID: 39644464
Perfect, thank you!
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 39661732
Well, to pull it together (though this already is solved):

If you do something like
Try
   Scan
     oBrowser.navigate2(url)
   Endscan
Catch
  * ...
Endtry

Open in new window

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

Open in new window


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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Insert into Excel a sum for three columns 8 695
Foxpro9 import of excel Table 4 620
Save Table Settings 6 269
Powershell script to Recycle processes all at once ( cleanly) 15 55
Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question