If (false == true) executes block when throwing exception is inside

后端 未结 2 436
萌比男神i
萌比男神i 2020-12-23 08:41

I have a rather strange problem that is occurring.

This is my code:

private async Task BreakExpectedLogic()
{
    bool test = false;
    if (test ==          


        
2条回答
  •  悲哀的现实
    2020-12-23 09:08

    It seems to be the bug in async method, the code is not actually executed but debugger steps to the line with throw statement. If there are some lines of code before throw statement inside if these lines are ignored, debugger steps only to the line with throw statement.

    Also, if you don't use variable - if (false) or if (true == false) then debugger steps to the correct line of code - to the closing curly brace.

    This bug has been posted by @Matthew Watson to Visual Studio team (link is not available now).

    Also, see similar question - Condition check in async method

    EDIT (2017/10/06):

    Issue cannot be reproduced in VS 2017 15.3.5 using .Net Framework 4.7. Seems like VS team has fixed this issue.

提交回复
热议问题