Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Try/Catch speed impact???
Message
From
19/11/2012 02:30:27
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
18/11/2012 23:25:40
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01557557
Message ID:
01557558
Views:
106
>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.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform