Search code examples
error-handlingfinallytry-catch-finally

Is there a way to handle error in a try-catch-finally if the error occurs after the finally block?


I was just curious. I have just written my first major code in C#, using try-catch-finally. I was wondering if there existed such a method to handle errors if there was additionally stuff to be processed after inside the finally block. Thanks.


Solution

  • You could nest another try-catch block in your finally clause (if I understand your question correctly):

    try
    {
    ...
    }
    catch
    {
    ...
    }
    finally
    {
        try
        {
        ...
        }
        catch
        {
        ...
        }
    }