Exception throws: encapsulate them or not?

Posted by Simon on Stack Overflow See other posts from Stack Overflow or by Simon
Published on 2010-06-03T16:30:00Z Indexed on 2010/06/03 16:34 UTC
Read the original article Hit count: 209

Filed under:
|
|
|

Hi there.

Once I read an MSDN article that encouraged the following programming paradigm:

public class MyClass
{
    public void Method1()
    {
        NewCustomException();
    }

    public void Method2()
    {
        NewCustomException();
    }

    void NewCustomException()
    {
        throw new CustomException("Exception message");
    }
}

Do you think this paradigm makes sense? Wouldn't it be enough to store the exception message in a static const field and then pass it to the exception's constructor, instead of encapsulating the whole exception throw?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET