发生异常后继续在 Visual Studio 调试器中 [英] Continuing in the Visual Studio debugger after an exception occurs

查看:35
本文介绍了发生异常后继续在 Visual Studio 调试器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调试一个 C# 程序并抛出异常(由代码抛出或由框架抛出)时,IDE 会停止并让我转到代码中的相应行.

When I debug a C# program and I get an exception throwed (either thrown by code OR thrown by the framework), the IDE stops and get me to the corresponding line in my code.

目前一切正常.

然后我按F5"继续.从这一刻开始,我仿佛陷入了无限循环.IDE 总是让我回到异常行.我必须Shift + F5(停止调试/终止程序)才能离开他.

I then press "F5" to continue. From this moment, it seams like I'm in an infinite loop. The IDE always get me back to the exception line. I have to Shift + F5 (stop debugging/terminate the program) to get out of his.

我和这里的一些同事交谈过,他们告诉我,这种情况有时也会发生在他们身上.

I talked with some co-workers here and they told me that this happens sometime to them too.

发生了什么?

推荐答案

这是因为未处理异常并且 Visual Studio 无法在没有以某种方式处理的情况下移过该行.简而言之,这是设计使然.

This is because the exception is un-handled and Visual Studio can not move past that line without it being handled in some manner. Simply put, it is by design.

您可以做的一件事是将执行点(黄线/箭头)拖放到代码中的前一个点并修改内存值(使用 Visual Studio 监视窗口),以免它们导致例外.然后再次开始单步执行代码1.

One thing that you can do is drag and drop the execution point (yellow line/arrow) to a previous point in your code and modify the in memory values (using the Visual Studio watch windows) so that they do not cause an exception. Then start stepping through the code again1.

最好停止执行并修复导致异常的问题,或者如果不希望抛出异常则正确处理异常.

It is a better idea though to stop execution and fix the problem that is causing the exception, or properly handle the exception if the throw is not desired.

1 这可能会产生意想不到的后果,因为您实际上是在重新执行一些代码(而不是回滚执行).

1 This can have unintended consequences since you are essentially re-executing some code (not rewinding the execution).

这篇关于发生异常后继续在 Visual Studio 调试器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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