Visual Studio:如何打破处理的异常? [英] Visual Studio: How to break on handled exceptions?

查看:145
本文介绍了Visual Studio:如何打破处理的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Visual Studio在处理异常发生时中断(即我不想看到第一次机会消息,我想调试实际的异常)。



例如我想要调试器在异常中断:

  try 
{
System.IO.File。删除(someFilename);
}
catch(异常)
{
//如果文件无法删除,我们真的不在乎运行时
}

我遇到了 Visual Studio.NET的这些注释:


1)在VS.NET中,转到调试菜单>>
异常...>>通用语言
运行时异常>>系统和
选择System.NullReferenceException



2)在该对话框的底部,
是当抛出异常时:
组框,选择Break into the
debugger / p>

3)运行您的方案。当抛出
异常时,调试器将
停止并通知一个对话框,
表示如下:
类型System.NullReferenceException的异常有
被抛出
[Break] [Continue]



点击[Break]。这将导致
的代码行导致
问题。


但是它们不适用到Visual Studio 2005(调试菜单中没有例外选项)。



有谁知道在Visual Studio中找到这个选项对话框,抛出异常组框,选择打破调试器



更新:问题是我的调试菜单没有例外项目。我定制菜单以手动添加它。


解决方案

解决方案打开后,转到调试 - 异常 Ctrl + D E )菜单选项。从那里你可以选择打破Thrown或用户未处理的异常。



编辑:我的实例是用C#配置文件设置的,也许它不存在其他资料?


I would like Visual Studio to break when a handled exception happens (i.e. I don't just want to see a "First chance" message, I want to debug the actual exception).

e.g. I want the debugger to break at the exception:

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

I came across these notes for Visual Studio.NET:

1) In VS.NET go to the Debug Menu >> "Exceptions..." >> "Common Language Runtime Exceptions" >> "System" and select "System.NullReferenceException"

2) In the bottom of that dialog there is a "When the exception is thrown:" group box, select "Break into the debugger"

3) Run your scenario. When the exception is thrown, the debugger will stop and notify you with a dialog that says something like: "An exception of type "System.NullReferenceException" has been thrown. [Break] [Continue]"

Hit [Break]. This will put you on the line of code that's causing the problem.

But they do not apply to Visual Studio 2005 (there is no Exceptions option on the Debug menu).

Does anyone know where the find this options dialog in Visual Studio that the "When the exception is thrown" group box, with the option to "Break into the debugger"?

Update: The problem was that my Debug menu didn't have an Exceptions item. I customized the menu to manually add it.

解决方案

With a solution open, go to the Debug - Exceptions (Ctrl+D,E) menu option. From there you can choose to break on Thrown or User-unhandled exceptions.

EDIT: My instance is set up with the C# "profile" perhaps it isn't there for other profiles?

这篇关于Visual Studio:如何打破处理的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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