Franr
Franr

Reputation: 35

Does try-catch-throw adds any value over no exception handling at all?

If you have a method like this:

public int Foo()
{
    try
    {
        // ...
    }
    catch(Exception)
    {
        throw;
    }
}

Assuming the exception is caught in another place, is this better than just having the method without any exception handling? Or this, on the other side, causes any disadvantage?

Upvotes: 2

Views: 114

Answers (2)

David Yaw
David Yaw

Reputation: 27874

At runtime, this doesn't change the behavior at all.

In the debugger, this gives you a place to put a breakpoint to break when an exception is thrown just in this one method. You can tell Visual Studio to break when certain exceptions are thrown, but that will break when they're thrown anywhere, not just in that one method.

Upvotes: 2

Reed Copsey
Reed Copsey

Reputation: 564851

is this better than just having the method without any exception handling?

No. This does nothing for you other than pass the exception through, which is the default behavior.

Personally, I think it's a bad practice, as having a try/catch suggests that you're doing some form of exception handling or going to do something with the exception.

Upvotes: 2

Related Questions