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()
中模拟 - 当调试器在异常抛出时继续中断时。
有没有办法在不编辑ThirdPartyLibrary代码的情况下避免这种情况(我不能轻易做到?)