How can I preserve exception context in an async console application using AsyncPump?

后端 未结 2 1342
心在旅途
心在旅途 2021-01-06 07:25

I am using Steven Toub\'s excellent AsyncPump class that allows console applications to use the async/await keywords.

However, I have a problem where exceptions that

2条回答
  •  暖寄归人
    2021-01-06 07:49

    GetAwaiter().GetResult() is already rethrowing exceptions properly (assuming you're on .NET 4.5). The call stack is properly preserved.

    What you're observing is the behavior of a top-level exception being caught, and AFAIK it is strictly treated by VS as synchronous and there's no way to influence that. Sounds like it would make a good UserVoice item.

    You do have the option of breaking when an exception is thrown.

提交回复
热议问题