how can I prevent swallowed exceptions in 3rd party libraries from triggering the VS debugger?

偶尔善良 提交于 2019-12-24 07:48:40

问题


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

As per here and here I understand you can use the [DebuggerHidden] attribute to prevent the debugger from stopping at a swallowed exception even if it is told to break on all thrown exceptions. This works for Test_ThrowSwallowLocal(). However I would like to duplicate this when calling code in a 3rd party library which is throwing and swallowing its own exceptions - which I am trying to emulate in Test_ThrowSwalloThirdParty() - at the moment the debugger continues to break at the exception throw.

Is there a way to avoid this without editing the ThirdPartyLibrary code (which I cannot easily do?)


回答1:


I would look into the Just My Code Option in VS



来源:https://stackoverflow.com/questions/10201622/how-can-i-prevent-swallowed-exceptions-in-3rd-party-libraries-from-triggering-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!