在Visual Studio 2017中的未处理异常后启用编辑

时间:2017-03-30 18:51:17

标签: c# visual-studio visual-studio-2017

如何在Visual Studio 2017中出现未处理的异常后继续执行?

在2015版及更低版本中,通过单击Enable Editing可轻松完成此操作,其中"将callstack展开到异常"之前的点。然后可以编辑执行点,变量和代码。

当库抛出异常时,此选项消失:

enter image description here

"".Substring(1);

如果用户代码中发生异常,它仍然有效:

enter image description here

int x = 0;
Console.WriteLine(1 / x);

注意可以拖动的黄色箭头。

我真的希望这个功能没有被删除,因为挽救崩溃的程序(例如,通过设置x = 1,例如更改字符串常量或跳过有问题的行)是我做了很多事情。现在我在这种状态下完成了99%的多小时操作,我真的很想通过抑制一个不重要的错误来拯救它。

这是.NET 4.6.1上的Visual Studio 2017 build 26228。

3 个答案:

答案 0 :(得分:2)

在VS2017中,隐藏并自动触发旧的“启用编辑”。在调试时,如果我执行以下操作,我可以在未处理的异常之后编辑代码/变量:

  1. 点击文档以关注新的例外助手
  2. 点击空格键(或您最喜欢的键!)
  3. OR

    1. 拖动黄色箭头(库的绿色箭头)。
    2. 在按键或移动箭头之前,文件选项卡上有挂锁,告诉您它已被编辑锁定。之后,锁定被移除,就像旧的“启用编辑”功能一样。删除编辑锁的第一次击键不会输入到文件中,之后编辑代码和变量就像以前一样。

      我更喜欢显式的“启用编辑”链接,就像以前一样,希望他们把它带回来。

答案 1 :(得分:0)

一次又一次地遇到这个问题,自从我切换到2017年以来,我终于找到了这个问题,并发现它实际上适用于来自"我的代码"的例外。谢谢你教我这个!

但是我也想知道它是否可能适用于"绿色箭头",它现在实际上有效!我正在运行15.2,所以如果它还没有为你工作,也许可以尝试升级到最新版本。

答案 2 :(得分:-3)

您可以让应用程序不向调试器发送异常:

import sys import numpy as np import matplotlib.pyplot as plt from scipy import stats from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QFileDialog, QTextEdit from PyQt5.QtGui import QIcon from PyQt5.QtCore import pyqtSlot class App(QWidget): def __init__(self): super().__init__() self.title = 'STATISTICIAN' self.initUI() def initUI(self): self.setWindowTitle(self.title) self.setGeometry(100, 100, 600, 600) button1 = QPushButton('1D statistics', self) button1.setToolTip('Start calculations of 1D statistics') button1.move(50, 25) button1.resize(500,70) button1.clicked.connect(self.on_click1) button2 = QPushButton('2D statistics', self) button2.setToolTip('Start calculations of 2D statistics') button2.move(50, 105) button2.resize(500,70) button2.clicked.connect(self.on_click2) ted = QTextEdit(self) ted.move(50, 250) ted.resize(500, 250) ted.setReadOnly(True) scrb = ted.verticalScrollBar() scrb.setValue(scrb.maximum()) self.show() @pyqtSlot() def on_click1(self): # Reading of data from file will be here # Some calculations will be here text = 'Results are:' # There will be finally more text ted.insertPlainText(text) # I'm trying to show results in QTextEdit (ted) def on_click2(self): print('2D statistics') print() if __name__ == '__main__': app = QApplication(sys.argv) ex = App() sys.exit(app.exec_())

在VS 2017中为我工作。