Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Try/Catch
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00802432
Message ID:
00802704
Views:
17
This message has been marked as a message which has helped to the initial question of the thread.
Eddie,

I would suggest to put all your code inside the TRY/CATCH block. Also, notice that CATCH has the option to "filter" errors, so that you can catch errors that you know how to handle (e.g. cannot open file for exclusive use) and let someone else (e.g.the caller program) deal with other errors.

I usually discourage people from using CATCH WHEN .T. since this will "eat" all errors, and your code most likely will not know how to deal with all errors. However, if you do add a CATCH WHEN .T. -- try to rethrow the exeption so that the caller program can deal with it (see commented code below).
try
    use customer excl
    close all
    do backups
catch TO oEx WHEN oEx.ErrorNo=3
    messagebox('Unable to Open Files Exclusive')
* catch
*   messagebox('something else went wrong')
*   throw
endtry
SET MARKETING ON
Here is yet another reference on Try/Catch:
http://www.levelextreme.com/magazine/june2003/page28.asp
SET MARKETING OFF
Hector Correa
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform