VS Express 2013 for Windows does not halt at the (async) line that throws an exception

泄露秘密 提交于 2020-01-25 02:17:25

问题


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];

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();

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?


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/26712785/vs-express-2013-for-windows-does-not-halt-at-the-async-line-that-throws-an-exc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!