dotnet / dotnet/dotnet-api-docs

Guidance on using IndexOutOfRangeException vs ArgumentOutOfRangeException

Open
#1,089 2 comments 4 reactions 0 assignees View on GitHub
area-System.Runtime dotnet-api/prod Pri2 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

I notice that accessing a List<T> by an incorrect index throws an ArgumentOutOfRangeException, not an IndexOutOfRangeException. I would have expected it to throw an IndexOutOfRangeException since it is more specific as to what the Range is.

Is there any guidance as to when to use one over the other?

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: e32ccb12-a1e2-6f9f-a626-837ae43d6902
* Version Independent ID: 1033266a-0616-dde9-7b1d-bc206496da2c
* Content: [IndexOutOfRangeException Class (System)](https://docs.microsoft.com/en-us/dotnet/api/system.indexoutofrangeexception?view=netframework-4.7.2)
* Content Source: [xml/System/IndexOutOfRangeException.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System/IndexOutOfRangeException.xml)
* Product: **dotnet-api**
* GitHub Login: @rpetrusha
* Microsoft Alias: **ronpet**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.