1
 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)
             {
             }
         }
     }
 }

根据herehere,我了解您可以使用该[DebuggerHidden]属性来防止调试器在被吞下的异常处停止,即使它被告知要中断所有抛出的异常。这适用于Test_ThrowSwallowLocal(). 但是,我想在第 3 方库中调用代码时复制它,该库抛出并吞下自己的异常——我试图在其中进行模拟Test_ThrowSwalloThirdParty()——此时调试器继续在抛出异常时中断。

有没有办法在不编辑 ThirdPartyLibrary 代码的情况下避免这种情况(我不能轻易做到?)

4

1 回答 1

2

我会研究VS 中的 Just My Code 选项

于 2012-04-18T01:53:05.960 回答