Here is CodeReview Guideline by Practice&Patterns team.http://msdn.microsoft.com/zh-cn/library/ms998574#scalenetchapt13_topic7(The link navigate to the Exception section automaticly.)
They said you should put try/catch block out of loop when you handle exception, I want to know why?
Because the underlying implementation of a
try... catchblock adds overhead to the generated code, and putting that overhead in a tight loop is not a good idea, performance-wise.Technically, if all the iterations of your loop are “equal”, and the loop should stop as soon as an exception occurs, then it’s better to put the
try... catchblock outside of the loop. If the loop must continue despite exceptions occurring, you’ll be forced to put the block inside the loop, but you might want to review your design in that case.