如何防止 3rd 方库中的吞食异常触发 VS 调试器? [英] how can I prevent swallowed exceptions in 3rd party libraries from triggering the VS debugger?

查看:26
本文介绍了如何防止 3rd 方库中的吞食异常触发 VS 调试器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

根据此处这里我知道你可以使用 [DebuggerHidden] 属性来防止调试器在吞下的异常处停止,即使它被告知要中断所有抛出的异常.这适用于 Test_ThrowSwallowLocal().但是,我想在调用 3rd 方库中的代码时复制这一点,该库正在抛出和吞下自己的异常 - 我试图在 Test_ThrowSwalloThirdParty() 中模拟 - 目前调试器继续中断在异常抛出处.

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.

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

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

推荐答案

我会查看 VS 中的我的代码选项

这篇关于如何防止 3rd 方库中的吞食异常触发 VS 调试器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆