为什么 Real Studio 在捕获异常时会中断?

发布于 2024-11-02 08:03:15 字数 228 浏览 1 评论 0原文

我有一个像这样的 try-catch 块:

Try
  Listbox1.RemoveRow(Listbox1.ListIndex)
Catch err As OutOfBoundsException
  MsgBox("Derp")
End Try

当我在调试器中运行我的项目时,我在我试图捕获的确切行上收到 OutOfBoundsException !为什么这不起作用?

I have a try-catch block like this:

Try
  Listbox1.RemoveRow(Listbox1.ListIndex)
Catch err As OutOfBoundsException
  MsgBox("Derp")
End Try

When I run my project in the debugger I get an OutOfBoundsException on the exact line I was trying to catch! Why doesn't this work?!?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十六岁半 2024-11-09 08:03:15

在我看来,调试器会在该行中断并向您显示异常。但是,如果您点击恢复,它将继续,捕获异常,然后显示消息。

也许他们在此版本中改变了调试器的行为。

更新:您可以转到“项目”>“中断异常以更改此设置

Seems to me like the debugger will break at that line and show you the exception. But if you hit resume, it will continue, catch the exception, and then display the message.

Maybe they changed the behavior of the debugger with this release.

Update: You can go to Project > Break on exception to change this

不必在意 2024-11-09 08:03:15

一旦遇到异常,调试器就会在执行任何其他代码之前中断。这包括您可能放入的任何异常处理代码(例如 Try...Catch 块)。

如果您有一些代码引发了很多异常,并且您不想每次调试时都逐句执行它,那么您有两个选择:核和外科手术。

核心选项是告诉调试器根本不要中断任何异常,这会产生不幸的副作用,即应用于整个项目而不是您要排除的一小部分项目。

外科手术的选择是使用 pragma 指令 在麻烦的地方关闭和打开异常代码:

#Pragma BreakOnExceptions Off
try
  Listbox1.RemoveRow Listbox1.ListIndex
catch err As OutOfBoundsException
  MsgBox "Derp"
End
#Pragma BreakOnExceptions On

这比简单地完全关闭部分调试器要好得多。注意:一旦函数返回,BreakOnExepctions 指令就会恢复为全局设置(打开或关闭),并且对于它周围的代码来说是本地的。

The debugger will break as soon as the exception is encountered, before any other code gets executed. This includes any exception handling code you may have put in like a Try...Catch block.

If you have a bit of code that raises a lot of exceptions and you'd rather not have to step through it every single time you debug, you have two options: nuclear and surgical.

The nuclear option is to tell the debugger to NOT break on any exceptions at all, which has the unfortunate side effect of applying to your entire project instead of the small portion of it you're excepting on.

The surgical option is to use pragma directives to toggle breaking on exceptions off and on around the troublesome code:

#Pragma BreakOnExceptions Off
try
  Listbox1.RemoveRow Listbox1.ListIndex
catch err As OutOfBoundsException
  MsgBox "Derp"
End
#Pragma BreakOnExceptions On

This is much more preferable then simply turning off part of the debugger altogether. Note: the BreakOnExepctions directive will revert to you global setting (on or off) as soon as the function returns and is local to the code it surrounds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文