Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
I want an error for VFP Open dialog
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00885697
Message ID:
00886006
Views:
30
>>Again, it's a feature. If you don't want it to occur, design accordingly.
>
>George, i agree with pretty much everything you say, it's better to code defensivly. But features can be changed, thats why the fox team added try-catch functionnality but to IMO they forgot to include a couple of things in it.
>
>Which of the following would you like better:
>
>try
>   Select MyCursor
>   Scan
>   ....
>   EndScan
>Catch
>   ....
>endtry
>
>Or
>
>try
>   If Used("MyCursor")
>     Select MyCursor
>     Scan
>     ....
>     EndScan
>   Else
>     Throw "Something"
>   Endif
>Catch
>   ....
>endtry
>
>
>The two method do exactly the same thing but i have 4 more line of code in the second one. Do you like to type for nothing?

Stephane,

Naturally, I would prefer the former. However, I should state that my opinion is that TRY..CATCH should be used to handle exceptions rather than errors. I know that some folks don't agree, but that's my feeling. Both it and ON ERROR should be used in complimentary fashion to each other. Simply put, I believe that there's a place for each.

However, your statement about number of lines of code reminds me of something I once read in Steve McConnell's book "Code Complete".

He had one line of code that occurred in about a dozen places in a program that involved division. At one point, he realized that the possibility of an error could occur because of division by zero. It would've have been an easy fix to simple check before the calculation was made. He, however, went further. He removed the calculation from being part of the in line code to a separate function. The net result was that instead of having to write and maintain 36 additional lines of code, there were only three and, instead of being spread out all over the program, it was in once place. There was an additional advantage. Instead of having a formula, he had a call to a function which, in turn, made the code self-documenting.

Well written code does this. It documents itself and, as a result, is not harder, but easier to read and understand.
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform