Possible Duplicate:
How slow are .NET exceptions?
Is there an overhead for throwing an exception and catching it right away? Is there a 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 don't throw 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?
Also I want to know why one solution is faster than another.