The link I provided in the above comment shows a description of why you shouldn't ever use a try-catch when an if-statement would prevent the exception from being thrown, but in the interest of showing performance in terms of actual numbers, I wrote this quick little test program.
Stopwatch watch = new Stopwatch(); int[] testArray = new int[] { 1, 2, 3, 4, 5 }; int? test = null; watch.Start(); for (int i = 0; i < 10000; i++) { try { testArray[(int)test] = 0; } catch { } } watch.Stop(); Console.WriteLine("try-catch result:"); Console.WriteLine(watch.Elapsed); Console.WriteLine(); watch.Restart(); for (int i = 0; i < 10000; i++) { if (test != null) testArray[(int)test] = 0; } watch.Stop(); Console.WriteLine("if-statement result:"); Console.WriteLine(watch.Elapsed);
The result of the program is this:
try-catch result: 00:00:32.6764911 if-statement result: 00:00:00.0001047
As you can see, the try-catch approach introduces significant overhead when an exception gets caught, taking over 30 seconds to complete 10,000 cycles on my machine. The if-statement, on the other hand, runs so fast that it is basically instantaneous. Compared to the try-catch, this is a performance improvement in the neighborhood of 3,000,000%.
(This isn't a rigorous benchmark, and there are ways to write it and run it differently to get more precise numbers, but this should give you a good idea of just how much more efficient it is to use an if-statement over a try-catch whenever possible.)
try..catchintroduces overhead and doesn't boost performance AFAIK.tryisn't slow,catchis.