Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Try/Catch
Message
From
20/06/2003 21:33:11
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00802432
Message ID:
00802518
Views:
14
Well, I don't know that I was that helpful after all. You're right that you cannot RETURN from a CATCH section, so the choice seem to be THROW or set a flag.

I think Try...Catch is one of those things that you have to work with for awhile before it begins to feel "right," but there are some situations where it is a lifesaver and can actually reduce code.

>Thanks Very Much David,
> Unfortunately Foxpro does not let us use a return statement in a Catch section which is what made me look for another way to go about this. I ended up setting a flag and handling it after the endtry. This works fine and all but it does make for program bloat and I like to keep my procedures lean which helps promote easier maintainability.
> I have previously read quite a few articles about try/catch/entry including Markus' and have been quite excited about it. But now that I actually have a chance to put it into use, I am somewhat dis-heartened that it appears that any implimentation of it leads to program bloat and possibly harder to read/understand/maintain code. Hopefully, someday the light will go on in my head and I will actually understand how to use this program structure in a way that really makes for better code.
>
>Eddie
>
>>
>>As Craig mentioned, Markus wrote a great tutorial which will take you step by step through learning the Try/Catch/Finally/EndTry syntax and strategies. What you will see when you read the article is that in your code sample below, the CLOSE ALL and DO Backups lines belong in the try section, because as written, your code will drop through to those lines even if you CATCH the error and show the messagebox. (Unless you THROW, RETURN, or otherwise EXIT the method from the CATCH section, execution will continue after the ENDTRY.)
>>
>>Or, as you hinted, you can set a flag (variable or property) in the CATCH and then check for the value after the ENDTRY (Markus illustrates that in the article), and then conditionally continue on to the CLOSE ALL and DO Backups. Or, with this approach, you can put the CLOSE ALL into a FINALLY section, which means that it will be executed after the TRY and CATCH, whether there was a problem or not.
>>
>>Bottom line: As with many things in VFP, there are many ways to approach the problem, and perhaps your doing what comes naturally wasn't such a bad idea to start with. :-)
>>
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Previous
Reply
Map
View

Click here to load this message in the networking platform