Visual Studio:如何处理exception处理?

我希望Visual Studio在处理exception发生时中断(即,我不只是想看到“First chance”消息,我想debugging实际的exception)。

例如,我想debugging器打破例外:

try { System.IO.File.Delete(someFilename); } catch (Exception) { //we really don't care at runtime if the file couldn't be deleted } 

我遇到了Visual Studio.NET的这些笔记:

1)在VS.NET进入debugging菜单>>“exception…”>>“公共语言运行时exception”>>“系统”并select“System.NullReferenceException”

2)在该对话框的底部有一个“当抛出exception时”组框,select“打入debugging器”

3)运行你的场景。 当引发exception时,debugging器将停止并通过一个对话框通知你:“types为”System.NullReferenceException“的exception已被抛出。[Break] [Continue]”

打[Break]。 这将使你在导致问题的代码行。

但它们不适用于Visual Studio 2005(“ debugging”菜单上没有“ exception”选项)。

有没有人知道在Visual Studio中find这个选项对话框的“ 何时抛出exception ”组框,并select“ 打入debugging器 ”?

更新:问题是我的debugging菜单没有一个例外项目。 我自定义菜单手动添加它。

打开一个解决scheme,进入debugging – 例外( Ctrl + DE )菜单选项。 从那里你可以select抛出抛出或用户未处理的exception。

编辑:我的实例设置与C#“configuration文件”也许它不是有其他configuration文件?

在VS2005中有一个“例外”窗口…在debugging时尝试Ctrl + Alt + E ,然后单击“Thrown”checkboxselect要停止的exception。

检查这在msdn上,它解释了如何设置。

基本上,这里是步骤(在debugging过程中):

  1. 在debugging菜单上单击例外。

  2. 在“例外”对话框中,为整个exception类别select“引发”,例如“公共语言运行时例外”。

    -要么-

    展开exception类别的节点(例如“公共语言运行时exception”),然后select“引发”(Thrown)作为该类别中的特定exception。

花了我一段时间find新的地方expect设置,因此一个新的答案。

从Visual Studio 2015开始,您可以控制在exception设置窗口(Debug-> Windows-> Exception Settings)中停止的exception。

处理自定义exception最简单的方法是select“不在此列表中的所有例外”。

我使用的技术如下所示。 定义一个全局variables,您可以使用一个或多个try catch块,具体取决于您要debugging的内容,并使用以下结构:

 if(!GlobalTestingBool) { try { SomeErrorProneMethod(); } catch (...) { // ... Error handling ... } } else { SomeErrorProneMethod(); } 

我发现这在testing方面给了我更多的灵活性,因为仍然有一些例外,我不希望IDE打破。

在线文档似乎有点不清楚,所以我只是做了一些小testing。 select从“exception”对话框抛出的exception会导致程序执行中断,处理或未处理任何exception。 如果你只想打破处理的exception,似乎你唯一的办法是通过你的代码,并把所有处理的exception放在断点上。 这似乎有点过分了,所以无论何时处理exception,都可以添加一个debugging语句。 然后当你看到输出时,你可以在代码中的那一行设置一个断点。