0
我正在運行此測試用例,並使用NUNIT並將NUNIT附加到Visual Studio調試器(Debug ---> Attach to Process ---> Select nunit 。可執行程序)。在c#中的try塊中拋出異常 - 通過將nunit附加到VSS調試器進行調試
我在等待語句「拋出新異常(」Exception 1 occured!「);」將控件移入catch塊但是 控件不會跳轉到「catch」,而是跳轉到method2() 。
當我只運行nunit測試用例而不將nunit.exe附加到Visual Studio調試器時,代碼的行爲正常。
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;
}
}
這是完全正確的。正如你在上面指出的那樣,在我的情況下,Visual Studio突出顯示即將運行的下一行代碼,而不是顯示拋出異常的那一行。當我繼續瀏覽代碼時 - 我確實接觸到catch塊。 – User1