Exception Handling. How long do they catch?

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.

+5
source share
3 answers

, , , . . , , . , . , .

, , .

+4

, Throw , try/catch. , /, , . , , , , .   , :

#, try, throw catch

try/catch #?

0

, , @Samuel Neff . , " " , : : ., . Infact :

1.2 :

, , , , , . . , . , . , , .

  • - , .
0

All Articles