I am currently using Visual Studio 2010 and I have a scenario I am currently facing in terms of code optimization of the catch block of a try statement
I wanted to know if there are any differences in using
catch (System.Exception e)
{
//log.Error(e.Message, e);//log specific type of error
if (e is ArgumentNullException)
{
//do something here
}
else if (e is SqlException)
{
//do something else
}
else if (e is NullReferenceException)
{
//do more things
}
else if (e is System.Exception)
{
//catch everything in site
}
}
as opposed to doing
catch (SqlException s)
{
//more things
}
catch (NotFiniteNumberException k)
{
//more errors
}
catch (System.Exception)
{
//all
}
This is scenario is based on logging the error on my part, in the first statement, I can log the error in one place and check its type, the second one is what I have been using so far, but then I would have to repeat the same line of logging the error.