Possible duplicate:
How slow are .NET exceptions?
Is there any overhead in throwing an exception and catching it right away? Is there any difference between this
void DoSomething(object basic)
{
try
{
if (basic == null)
throw new NullReferenceException("Any message");
else
{
}
}
catch (Exception error)
{
_logger.WriteLog(error);
}
}
and this (here we are not throwing an exception):
void DoSomething(object basic)
{
try
{
if (basic == null)
{
_logger.WriteLog(new NullReferenceException("Any message");
return;
}
else
{
...
}
}
catch (Exception error)
{
_logger.WriteLog(error);
}
}
Will the second fragment be faster or not?
I also want to know why one solution is faster than another.
source
share