Hi there,
Sorry if the question is a bit vague. I have some code surrounded by a try catch. The piece of code can potentially take hours to compute.
I'm wondering is there a performance hit is using a try catch? If there is are we talking a 10% hit? More?
Loading
KevinPosted Sep 17, 2008, 8:32 AM
Ryan AlfordPosted Sep 16, 2008, 3:43 PM
AlanPosted Sep 16, 2008, 12:27 PM
KevinPosted Sep 16, 2008, 11:39 AM
try
{
object a = Method();
}
catch(System.Exception m)
{
MessageBox.Show(m.Message);
}
finally
{
//Cuts a thread elsewhere
}
AlanPosted Sep 16, 2008, 11:29 AM
There is a performance hit in using try/catch/finally but how big it is will depend on:
1. What you're doing within the try statement.
2. The additional cost of doing something else (such as testing a method return value) if there's an error.
In view of this it's very difficult to put a figure on it but, if you think in terms of a 10 to 20% hit on average, then I don't think you'll be far away.