To Throw or Not to Throw

Posted by serhio on Stack Overflow See other posts from Stack Overflow or by serhio
Published on 2010-03-25T11:51:27Z Indexed on 2010/03/25 12:03 UTC
Read the original article Hit count: 441

// To Throw
void PrintType(object obj)
{
    if(obj == null) 
    {
        throw new ArgumentNullException("obj")
    }

    Console.WriteLine(obj.GetType().Name);    
}

// Not to Throw
void PrintType(object obj)
{
    if(obj != null)
    {
        Console.WriteLine(obj.GetType().Name);
    }
}

What principle to keep? Personally

Personally I prefer the first one its say developer-friendly. The second one its say user-friendly.

What do you think?

© Stack Overflow or respective owner

Related posts about exception-handling

Related posts about language-agnostic