Exception Handling without catch(Exception)

The design guidelines for exception handling are quite clear on avoiding “catch all” and/or avoiding catching exceptions you can’t handle. But there are cases when you really need to know if the try block completed successfully or not, and possibly take some action.

One way one could achieve this without breaking the guideline is to set a flag at the end of the try block and then query it inside finally:

bool workCompleted = false;

try

{

    DoSomething();

    DoSomethingMore();

    workCompleted = true;

}

finally

{

    if (!workCompleted)

    {

        Console.WriteLine("record that the work failed");

    }

}