[英]f# exception raised out of order in a loop
Is there a reason why the exception is displayed before the function has even started in the following? 在以下功能尚未启动之前,为什么会显示异常?
let listCharacters (text:string) =
let stripv3 = text.Split([|' '|], System.StringSplitOptions.RemoveEmptyEntries) |> System.String.Concat
for i in 0..2..stripv3.Length do
let char = stripv3.Chars(i)
if char <> ' ' then
printfn "%c" char
listCharacters "honey badger is a badass"
Produces the following output:- 产生以下输出:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
h
n
y
a
g
r
s
b
d
s
Interestingly if I add a try..with
any operations within the with occurs in order, any ideas why this is? 有趣的是,如果我添加一个
try..with
任何操作按顺序发生,为什么会这样呢?
To summarise the comments above the problem is specific to the IDE and not to the language. 总结上面的评论,问题是特定于IDE而不是语言。
In this instance the issue was only seen in the Visual Studio F# Interactive view. 在这种情况下,只能在Visual Studio F#交互式视图中看到该问题。
When executed fully or run via Visual Studio FSI.exe the exception was the last item to be output. 当完全执行或通过Visual Studio FSI.exe运行时,例外是要输出的最后一项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.