Use .TryParse instead of Try {} Catch {}
In certain conditions, we should not be using exceptions. For example, Try Catch blocks can be avoided in certain cases. If you have some .NET 1.0 code, you might not be taking advantage of .NET 2.0 new TryParse functions, which avoid exception handling and are much faster.
For example:
try
{
iEditMode = Convert.ToInt32(strEditMode);
}
catch
{
iEditMode = 0;
}
In this case, we have TryParse functions which were added in .NET 2.0
Better to instead do:
if (!Int32.TryParse(strEditMode, out iEditMode))
{
iEditMode = 0;
}
Much better performance, no need to handle clunky exceptions :) Thank you to Brendan for correcting my error above. (missing out keyword)
MSDN in regards to exception handling states, "Do not use exception handling for flow of control, only for failure situations."
Resources