Skip to content

Commit b25b426

Browse files
authored
Fix exception throwing inconsistency (#17328)
* Fix exception throwing inconsitency * release notes * Update 8.0.400.md
1 parent 41cd736 commit b25b426

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docs/release-notes/.FSharp.Core/8.0.400.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66

77
* Cache delegate in query extensions. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130))
88
* Update `AllowNullLiteralAttribute` to also use `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173))
9+
10+
### Breaking Changes
11+
12+
* Fixed argument exception throwing inconsistency - accessing an out-of-bounds collection index will now throw `ArgumentOutOfRangeException` instead of `ArgumentException` ([#17328](https://github.com/dotnet/fsharp/pull/17328))

src/FSharp.Core/local.fs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ module internal DetailedExceptions =
1414
let msg = String.Format (format, paramArray)
1515
raise (new ArgumentException (msg, arg))
1616

17+
/// takes an argument, a formatting string, a param array to splice into the formatting string
18+
let inline invalidArgOutOfRangeFmt (arg:string) (format:string) paramArray =
19+
let msg = String.Format (format, paramArray)
20+
raise (new ArgumentOutOfRangeException (arg, msg))
21+
1722
/// takes a formatting string and a param array to splice into the formatting string
1823
let inline invalidOpFmt (format:string) paramArray =
1924
let msg = String.Format (format, paramArray)
@@ -38,7 +43,6 @@ module internal DetailedExceptions =
3843
"{0}\nThe list was {1} {2} shorter than the index"
3944
[|SR.GetString SR.notEnoughElements; index; (if index=1 then "element" else "elements")|]
4045

41-
4246
/// eg. tried to {skip} {2} {elements} past the end of the seq. Seq.Length = {10}
4347
let invalidOpExceededSeqLength (fnName:string) (diff:int) (len:int) =
4448
invalidOpFmt "{0}\ntried to {1} {2} {3} past the end of the seq\nSeq.Length = {4}"
@@ -52,11 +56,11 @@ module internal DetailedExceptions =
5256
let inline invalidArgInputMustBePositive (arg:string) (count:int) =
5357
invalidArgFmt arg "{0}\n{1} = {2}" [|SR.GetString SR.inputMustBePositive; arg; count|]
5458

55-
/// throws an invalid argument exception and returns the out of range index,
59+
/// throws an invalid argument out of range exception and returns the out of range index,
5660
/// a text description of the range, and the bound of the range
5761
/// e.g. sourceIndex = -4, source axis-0 lower bound = 0"
5862
let invalidArgOutOfRange (arg:string) (index:int) (text:string) (bound:int) =
59-
invalidArgFmt arg
63+
invalidArgOutOfRangeFmt arg
6064
"{0}\n{1} = {2}, {3} = {4}"
6165
[|SR.GetString SR.outOfRange; arg; index; text; bound|]
6266

0 commit comments

Comments
 (0)