>>> 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.
Hector Correa