VS Express 2013 for Windows 不会在引发异常的(异步)行停止 [英] VS Express 2013 for Windows does not halt at the (async) line that throws an exception

查看:24
本文介绍了VS Express 2013 for Windows 不会在引发异常的(异步)行停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对异步编程非常陌生.当抛出异常时,我习惯于 Visual Studio 停在错误的行上.在如下代码中,调试器通常会停止并突出显示第 2 行

I am very new to async programming. When an exception is thrown, I am used to Visual Studio to halt at the erroneous line. In a code like the following, the debugger normally stops and highlights line 2

int[] array = new int[] { 0, 1, 2 };
int throwsException = array[3];

但是当使用 await 调用的方法中发生异常时,我完全迷失了方向,调试器只是停在 await 行.

But when an exception occurs in a method that is called with await, than I am completely lost and the debugger simply stops at the await line.

public async void ThrowException() {
    int[] array = new int[] { 0, 1, 2 };
    int throwsException = array[3];
}

// Debugger stops here
await ThrowException();

问题是,我有一个等待方法,它会在第 100 次和第 200 次调用之间的某个地方抛出错误.我不知道如何在调试器中识别问题!有没有办法轻松识别有问题的代码行?

The problem is, that I have an await-method that throws an error somewhere between the 100th and 200th time it is called. I have no clue how to identify the problem in the debugger! Is there a way to easily identify the problematic line of code?

推荐答案

您可以选择调试器将在哪些异常上停止,去检查 Visual Studio 中的调试/异常选项.

you can select on which exceptions the debugger will stop, go to check the debugging/exceptions options in your visual studio.

http://msdn.microsoft.com/en-us/library/038tzxdw.aspx

它看起来确实是一些内部 Windows 错误,因此如果未配置调试器可能不会在那里停止,因此您可以将 Visual Studio 配置为即使在最内部的 Windows 异常中也停止,然后查看调用堆栈.

it does look like it is some internal windows error so the debugger might not stop there if it is not configured, so you can configure visual studio to stop even in the most inner windows exceptions and then look at the call stack.

或者您可以使用 try/catch 块将代码包装在public async void ThrowException()"函数中,并在 catch 中放置一个断点

Or you can wrap your code inside the "public async void ThrowException()" function with a try/catch block and put a break point inside the catch

这篇关于VS Express 2013 for Windows 不会在引发异常的(异步)行停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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