After scenario Cleanup in Specflow - try catch finally

1.1k Views Asked by At

I am try to clean up the scenario by capturing screenshots

The problem I face is when I try to see how many times "try catch finally" is executed..it's executed nearly 20 times after initial try-finally-it goes directly to catch

Here is my code

 [AfterScenario]
    public void CleanUp()
    {
        int aaa = 0;
        try
        {

            if (ScenarioContext.Current.TestError != null)
            {
                //Taking screenshot

            }
            Console.WriteLine("try");
        }
        catch
        {
            Console.WriteLine("Catch");
            if (Browser != null)
            {
                Browser.Dispose();
                Browser = null;

            }
            return;
        }
        finally
        {
            Console.WriteLine("finally");
                if (Browser != null)
                {
                    Browser.Dispose();
                    Browser = null;
                    Console.WriteLine("finallya");
                }

        }
        return;
    }

try finally

after this why it goes to Catch again? when I am doing some thing wrong here?

0

There are 0 best solutions below