bad performance from too many caught errors?
- by Christopher Klein
I have a large project in C# (.NET 2.0) which contains very large chunks of code generated by SubSonic. Is a try-catch like this causing a horrible performance hit?
for (int x = 0; x < identifiers.Count; x++)
{decimal target = 0;
try
{
target = Convert.ToDecimal(assets[x + identifiers.Count * 2]); // target %
}
catch { targetEmpty = true; }}
What is happening is if the given field that is being passed in is not something that can be converted to a decimal it sets a flag which is then used further along in the record to determine something else.
The problem is that the application is literally throwing 10s of thousands of exceptions as I am parsing through 30k records. The process as a whole takes almost 10 minutes for everything and my overall task is to improve that time some and this seemed like easy hanging fruit if its a bad design idea.
Any thoughts would be helpful (be kind, its been a miserable day)
thanks,
Chris