Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Try...catch...finally
Message
From
27/10/2002 11:27:31
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00715709
Message ID:
00715881
Views:
16
OK, thanks.

>>>> Will CATCH able to "catch" the error if OLE ERROR raised?
>>>Yes, it does.
>>
>>I have another question about the TRY. What is the FINALLY for? Specifically, is there a difference between placing commands after FINALLY, or completely outside the entire TRY structure?
>>
>>Hilmar.
>As Alex mentioned, the code inside the FINALLY block *always* gets executed. Even when the exception is not handled by the TRY/ENDTRY block.
>
>For example, the error in the following code will be handled by the ON ERROR clause since it does not matches with the CATCH...TO...WHEN clause. However, despite the fact that the CATCH will not handle the exception (it will be passed to the ON ERROR) the code in the FINALLY block will be executed but not the code after it.
>
>
>clear
>on error cancel
>
>? "before try"
>try
>	? "try"
>	H = "4" + 5	
>catch to oEx when oEx.ErrorNum = 1
>	? "catch"
>finally
>	? "finally"
>endtry
>? "after try"
>
>
>In other languages, there is an additional reason to have FINALLY clause and that reason is variable scoping. In other languages if you declare a variable *inside* the TRY/ENDTRY block, this variable is *not* visible outside of it. Therefore, FINALLY is very nice in those cases since you can still use that variable. This is not necessary in VFP since a variable declared inside the TRY/ENDTRY block will be visible outside of it.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform