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

Fix exception throwing inconsistency #17328

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/FSharp.Core/local.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ module internal DetailedExceptions =
let msg = String.Format (format, paramArray)
raise (new ArgumentException (msg, arg))

/// takes an argument, a formatting string, a param array to splice into the formatting string
let inline invalidArgOutOfRangeFmt (arg:string) (format:string) paramArray =
let msg = String.Format (format, paramArray)
raise (new ArgumentOutOfRangeException (arg, msg))
psfinaki marked this conversation as resolved.
Show resolved Hide resolved

/// takes a formatting string and a param array to splice into the formatting string
let inline invalidOpFmt (format:string) paramArray =
let msg = String.Format (format, paramArray)
Expand All @@ -38,7 +43,6 @@ module internal DetailedExceptions =
"{0}\nThe list was {1} {2} shorter than the index"
[|SR.GetString SR.notEnoughElements; index; (if index=1 then "element" else "elements")|]


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

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

Expand Down
Loading