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
Use ThrowHelper methods in more places #6184
Conversation
Use ArgumentNullException.ThrowIfNull in more places part 2
22e2ac5
to
ffdb229
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok but some error messages have changed for the worse.
if (minSize > maxSize) | ||
throw new ArgumentOutOfRangeException(nameof(minSize), $"Must be less than {nameof(maxSize)}."); | ||
ArgumentOutOfRangeException.ThrowIfNegative(minSize); | ||
ArgumentOutOfRangeException.ThrowIfGreaterThan(minSize, maxSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that maxSize
no will longer appear in the error message.
master:
System.ArgumentOutOfRangeException : Must be less than maxSize. (Parameter 'minSize')
This PR:
System.ArgumentOutOfRangeException : minSize ('20') must be less than or equal to '10'. (Parameter 'minSize')
Actual value was 20.
if (minValue > maxValue) | ||
throw new ArgumentOutOfRangeException(nameof(minValue), "The given minimum value must be less than or equal to the given maximum value."); | ||
ArgumentOutOfRangeException.ThrowIfGreaterThan(minValue, maxValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See other comment about maxValue
/maxSize
no longer appearing in the error message. Same applies for the other usage of ThrowIfGreaterThan()
in this file.
I've addressed some of the comments. Should I also revert all usages of ThrowIfGreaterThan() to retain the max value in the error message, or is it fine like that? |
Related: #3470 |
The other path I can suggest is to make an |
I personally don't feel the exception message matters that much. Sure it might be a little bit cryptic, but the "must be greater than"/"must be lower than" is already giving it out I think. |
My view on the Which this does, so I'm fine with this. The fact that it doesn't print the name of the other value feels whatever. |
All comments have been addressed. |
throw
to promote inlining #3470ObjectDisposedException.ThrowIf(), ArgumentException.ThrowIfNullOrEmpty() and the ArgumentOutOfRangeException methods have been introduced in .NET 7/8