f# - more descriptive IndexOutOfRangeException -
is there way more descriptive index-out-of-range-exceptions ? thought overriding item property this, not work:
type ``[]``<'t> override arr.item get(i) = if i<0 || >= arr.length failwithf "index %d out of range on array(%d): %a" arr.length arr else arr.[i] , set (i: int) (value:'t) = arr.[i] <- value
if debugging can configure vs break on clr exceptions (debug > exceptions...) see invalid index. otherwise, this:
let idx = -1 try arr.[idx] <- x :? system.indexoutofrangeexception -> failwithf "index out of range: %d" idx another option shadow array.get/array.set:
module array = let (arr: 't[]) = if i<0 || >= arr.length failwithf "index %d out of range on array(%d): %a" arr.length arr else arr.[i]
Comments
Post a Comment