How can I make VS break on exceptions in an async Task, without breaking on all exceptions?

前端 未结 5 744
小蘑菇
小蘑菇 2021-02-01 15:06

As indicated here and here, exceptions occuring in an async Task are technically not unhandled.

This is particularly nasty when working with MVC. It actually took us a w

5条回答
  •  花落未央
    2021-02-01 15:28

    A) Wrap your calls and throw a custom Exception in your Task code. Break on only throw of your custom exception. You can select the Exceptions for first throw.

    B). Debug.Assert() your Task Results, if you have any wait code. i.e., not just firing and forgetting. Tasks return the Exceptions in a property if you wait on them somewhere or stick error handling in a continuation.

    psuedo code i.e. task. continuewith(r => if(!r.Exception is null) Debug.Break())) etc.

    Hope that helps you on the right path.

提交回复
热议问题