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:
00802530
Views:
20
>> 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 would actually disagree with this statement. TRY/CATCH in fact reduces program bloat drastically, since you do not need lots and lots of lines of defensive code. You are correct that your code will be bigger with the try catch than without it. But if you added regular error handling, the bloat would be enormous.

At my session at DevCon I showed some very simple examples. 3 or 4 lines of code to access a database. With pre-T/C code, the code bloats to 60 lines of code or more to make things bullet proof. With T/C, error handling adds 3 or 4 lines.

I agree that it would be nice to be able to return out of the catch. But you can easily work around it like so:

LOCAL llRetVal
llRetVal = .T.
TRY
USE Table Excl
CATCH
llRetVal = .F.
ENDTRY
RETURN llRetVal

Note that many people (including myself) would consider it bad style to have multiple return pionts from a method (with very few exceptions).

Markus




Markus Egger
President, EPS Software Corp
Author, Advanced Object Oriented Programming with VFP6
Publisher, CoDe Magazine
Microsoft MVP since 1995
Previous
Reply
Map
View

Click here to load this message in the networking platform