>Does anyone know the speed impact of using Try/Catch statements in VFP code? My intuition says there must be some hit, but I'm just curious if anyone has any hard data or real world experience with quantifying the performance hit of using this???
>
>For instance, here is the defensive use of Try/Catch I am contemplating. It guards against cases where a property name does not exist on an object. This code will be called very frequently in my app, so I want to make sure it's as fast as possible, but I still need a safety net in case the property name is not on the object.
>
>
>
>Local lcFKDataType
>
>Try
> lcFKDataType = Vartype(GetPem(This.oData, This.cFKField))
>Catch
> lcFKDataType = 'U'
>Finally
>EndTry
>
>Return lcFKDataType
>
>
I don't think there's any hit at all, because there is always some error handling. If you do none, there's the code which will display the "cancel - [supend] - ignore - help" dialog. It's only a matter how will the error handling be redirected - left on default, handled by class code, by try/catch, or by on("error") code.
OK there would be some hit - as long as it takes to execute one command which writes an address of some code to a location in memory, but that shouldn't be much.
BTW, in this case you can avoid it completely with
lcDataType=iif(pemstatus(this.odata, this.cFKField, 5), vartype(getpem(This.oData, This.cFKField)), "U")
Because it seems you are checking a scatternamed object. With most of the other objects there's a chance that this wouldn't work if you hit a hidden or protected property anywhere up the class hierarchy.