Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWEEP: Replace IndexOutOfRangeException with ArgumentOutOfRangeException except for indexer use, #1023 #1083

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

paulirwin
Copy link
Contributor

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

Replaces IndexOutOfRangeException use with ArgumentOutOfRangeException when thrown from a method rather than an indexer.

Fixes #1023

Description

It is not correct in .NET to use IndexOutOfRangeException to throw exceptions from a non-indexer method when an argument is out of range, even if that argument is named index; that is what ArgumentOutOfRangeException is for. Additionally, this has the added benefit of having the paramName set to know which argument is out of range.

@paulirwin paulirwin added the notes:improvement An enhancement to an existing feature label Jan 2, 2025
@paulirwin paulirwin merged commit dbc602c into apache:master Jan 2, 2025
267 checks passed
@paulirwin paulirwin deleted the issue/1023 branch January 2, 2025 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notes:improvement An enhancement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use ArgumentOutOfRangeException instead of IndexOutOfRangeException outside of indexers
1 participant