Home

5.0.4 - when exception thrown, marked line is 1 below the one that threw?

I think I had seen this on occasion in linqpad 4, but in case it's something fixable during the 5 beta, wanted to mention it. The squiggle and gutter marker seem like they should be on the line above AFAICT?

image

source (I was just showing a co-worker that you can get different values, the logic isn't really important)
var loopCount = 1;
while (true)
{
    var foo = DateTime.UtcNow;
    var bar = DateTime.UtcNow;
    if (foo != bar) throw new Exception($"different values found in loop {loopCount}: {foo.Ticks} and {bar.Ticks}");
    loopCount++;
}

Comments

  • This happens only with the 64-bit version, right?

    If so, this is a bug/quirk of the 64-bit CLR. You can reproduce this in Visual Studio: put a try/catch around the code in question and examine the exception's StackTrace property. In 64-bit mode, it reports the position of the next instruction to be executed rather than the line that threw.
  • well, that explains why I saw it sometimes and not others with LINQPad 4!

    Thanks, Joe!
Sign In or Register to comment.