Reputation:
I am running this test case using NUNIT and attaching the NUNIT to the Visual studio debugger (Debug ---> Attach to Process ---> Select nunit.exe).
I was expecting the statement "throw new Exception("Exception 1 occured!");"to move the control into the catch block but the control does not jump to the "catch" but instead jumps to method2().
When I just run the nunit test case without attaching nunit.exe to the Visual Studio debugger the code behaves normally.
public void test()
{
try
{
method1();
if (condition1)
{
throw new Exception("Exception 1 occured!");
}
method2();
if (condition2)
{
throw new Exception("Exception 2 occured!");
}
method3();
if (condition3)
{
throw new Exception("Exception 3 occured!");
}
}
catch (Exception Ex) <---- Exceptions thrown above are caught here
{
logMessage(E.Message);
throw;
}
}
Upvotes: 0
Views: 260
Reputation: 156748
Visual Studio is probably set to break on all Exceptions instead of just uncaught Exceptions. So it stops when it detects that you threw the Exception. In certain cases, rather than appearing to break on the line that throws the exception, Visual Studio highlights the next line of code which was about to run.
If you continue to step through the code, you should see it go to the catch
block next.
Upvotes: 0