Skip to content

Include actual index in IndexOutOfRange message #27878

@danmoseley

Description

@danmoseley

When testing, if you hit an IndexOutOfRangeException through out of bounds array access, it is sometimes helpful to know what the index was, to save firing up a debugger (if it will even repro).

In this context the exception is instantiated by the VM/JIT. I do not know whether this would affect performance.

 System.IndexOutOfRangeException : Index was outside the bounds of the array.
Stack Trace:
   at Microsoft.Collections.Extensions.DictionarySlim`2.Enumerator.MoveNext() in C:\git\corefxlab\src\Microsoft.Experimental.Collections\Microsoft\Collections\Extensions\DictionarySlim.cs:line 284
   at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
   at Microsoft.Collections.Extensions.Tests.DictionarySlimTests.EnumerateCheckEnding() in C:\git\corefxlab\tests\Microsoft.Experimental.Collections.Tests\DictionarySlimTests.cs:line 150

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.CollectionsenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions