-3

I have a for loop that contains a try-catch block:

for ..
{
   try
           {
                ...
           }
   catch (Exception ex)
           {
               throw ex;
           }
}

Now, if I will re-throw an exception and will catch it in the calling method, will the program continue from the next iteration? (after the external catch block).

TY!

1 Answers1

1

No it will not. With throw you leave the current method (if you don't catch it in this method), so it is like a return. If you catch the Exception in an outer method, the program will continue with the outer method:

private void innerMethod()
{
    try 
    {
        throw;
    }
    catch
    {
        throw;
    }
    someMethodThatWillNotBeExecuted();
}

public void outerMethod()
{
    try 
    {
        innerMethod();
    }
    catch
    {
        thisWillBeExecuted();
    }
    thisWillAlsoBeExecuted();
}
Fabian S.
  • 909
  • 6
  • 20