using System;
using System.Diagnostics;
using NUnit.Framework;
namespace TestExperiment
{
[TestFixture]
internal class TestAAA
{
[Test]
public void Test_ThrowSwallowThirdParty()
{
ThrowSwallowThirdParty();
}
[Test]
public void Test_ThrowSwallowLocal()
{
ThrowSwallowLocal();
}
[DebuggerStepThrough]
[DebuggerNonUserCode]
[DebuggerHidden]
public void ThrowSwallowThirdParty()
{
ThirdPartyLibrary.ThrowEmbedded();
}
[DebuggerStepThrough]
[DebuggerNonUserCode]
[DebuggerHidden]
public void ThrowSwallowLocal()
{
try
{
throw new Exception();
}
catch (Exception e)
{
}
}
}
// imagine this is a 3rd party library provided in a dll which I am referencing
internal static class ThirdPartyLibrary
{
public static void ThrowEmbedded()
{
try
{
throw new Exception();
}
catch (Exception e)
{
}
}
}
}
按here和here我知道你可以使用[DebuggerHidden]
屬性來阻止調試器,即使它被告知所有拋出的異常打破在吞嚥異常停止。這適用於Test_ThrowSwallowLocal()
。不過,我想在第三方庫中調用代碼的時候重複這個操作,它拋出併吞下它自己的異常 - 我試圖模擬Test_ThrowSwalloThirdParty()
- 此時調試器在異常拋出時繼續中斷。我該如何防止第三方庫中的吞嚥異常觸發VS調試器?
有沒有辦法避免這種不編輯ThirdPartyLibrary代碼的方式(我不能輕易做什麼?)
這是在Visual Studio中調試時或剛運行的應用程序? – 2012-04-18 01:38:48
在visual studio中調試 – fostandy 2012-04-18 01:51:41
它曾經在VS2012之前工作得很好 – Patrick 2013-01-16 18:41:30