bad performance from too many caught errors?
        Posted  
        
            by Christopher Klein
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Christopher Klein
        
        
        
        Published on 2010-04-22T21:19:36Z
        Indexed on 
            2010/04/22
            21:23 UTC
        
        
        Read the original article
        Hit count: 349
        
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
© Stack Overflow or respective owner