有没有办法防止Visual Studio在特定方法中突破异常? [英] Is there a way to prevent Visual Studio from breaking on exceptions in a specific method?

查看:122
本文介绍了有没有办法防止Visual Studio在特定方法中突破异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以控制Visual Studio根据他们的类型处理异常的方式,以及最终被抓住使用异常对话框的事实。

I know I can control the way Visual Studio handles exceptions according to their type and to the fact that they're eventually caught using the "Exception" dialog.

但是,当我调用一个特定的方法时,我有一个库内部抛出(和捕获)一个 ArgumentOutOfRange 异常。异常被抛出(也被图书馆所捕获)也许是1%的时间,但是我打电话给这个方法很多。编辑说这是按设计(确实是他们选择的设计是有意义的)。

However, I've got a library that's internally throwing (and catching) an ArgumentOutOfRange exception when I'm calling a specific method. The exception is thrown (and caught by the library) maybe 1% of the time, but I'm calling this method a lot. The editor says it's by design (and indeed, the design they've chosen makes sense).

事情是,我不希望Visual Studio每次打破抛出异常。

The thing is that I don't want Visual Studio to break each time the exception is thrown.


  • 我不想停止打破 ArgumentOutOfRange 例外,因为我可能有一些在我的代码,并希望打破那些。

  • 我不想启用只是我的代码调试,因为我担心抛出的异常在我的代码之外(特别是出于性能原因)

  • I don't want to stop breaking on ArgumentOutOfRange exceptions, as I may have some in my code and want to break on those.
  • I don't want to enable "just my code" debugging because I'm concerned about the exceptions thrown outside of my code (notably for performance reasons)

有没有办法实现?我一直在研究属性(例如 DebuggerStepThrough ),但尚未找到足够的东西。

Is there a way to achieve this? I've been looking into attributes (such as DebuggerStepThrough), but haven't find something adequate yet.

任何提示如何做到这一点?

Any hints on how to do this ?

推荐答案


我不想启用只是我的代码调试

I don't want to enable "just my code" debugging

是的,现在就停在那里。那就是你所需要的功能,不要让不必要的调试器中断。如果你不想知道别人的肮脏的代码,那么再翻转一下这个复选框。

Yeah, stop there right now. That is exactly the feature you need to not get the unwanted debugger breaks. If you don't want to know about somebody else's crappy code then flip that checkbox back on.

当程序员使用异常来控制流量时,这一切总是脱轨。一个非常常见的罪行。它们需要两个来将它变成一个混乱,将调试会话变成一个非常乏味的点击噩梦。当你需要调试器功能打破第一次机会异常时,如果还有人需要,你基本上会失去。

This invariably goes off the rails when programmers use exceptions for flow control. A very common crime. It takes two of them to turn that into a mess that turns a debugging session into a very tedious click nightmare. When you need the debugger feature that breaks on the first-chance exception then you basically lost if somebody else needed that as well.

每个人都希望他们可以神奇地使用[ DebuggerNonUserCode]或[DebuggerHidden]或[DebuggerStepThrough]属性,使该问题消失。没有另一位程序员并没有认为他的代码不够重要,不应该拥有这些属性。而且,这并不是因为在使用try / catch-em-all代码的代码中总是存在一个bug。口袋妖怪代码。

Everybody hopes that they can magically use the [DebuggerNonUserCode] or [DebuggerHidden] or [DebuggerStepThrough] attributes to make that problem disappear. It doesn't. The other programmer did not think his code was unimportant enough to deserve those attributes. And, well, it wasn't because there's always a bug hidden in code that uses try/catch-em-all code. Pokémon code.

所以微软不得不找到另一种方式来帮助程序员处理拙劣的库代码。他们做到了。勾选该复选框,bam,解决。无论如何,除了向作者发送一个讨厌的克隆之外,你还可以做任何关于这个糟糕的代码的事情。不要让我们或微软慢下来,所以我们必须一起创造一个人们喜欢使用的产品。

So Microsoft had to find another way to help programmers deal with crappy library code. They did. Tick that checkbox, bam, solved. Nothing you can do about that crappy code anyway, other than sending a nasty-gram to the author. Don't let us or Microsoft slow you down doing that as well, y'all have to get along to create a product that people like to use.

这篇关于有没有办法防止Visual Studio在特定方法中突破异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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