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

查看:150
本文介绍了发生异常后继续在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在这里与一些同事交谈,他们告诉我,这也发生在他们的某个时间。

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天全站免登陆