Exception handling 匹配构造函数中的System.TypeInitializationException异常

Exception handling 匹配构造函数中的System.TypeInitializationException异常,exception-handling,f#,typeinitializeexception,Exception Handling,F#,Typeinitializeexception,我试图从F4.0 VS2015中的字符串中获取一个有区别的联合类型。我的代码如下所示: type FooOrBar =Foo | Bar let FooOrBarFromString str = match str with | "Foo" -> Foo | "Bar" -> Bar | _ -> raise (System.ArgumentException("Invalid input")) 问题是,如果触发默认条件并引发异常,则参数异常

我试图从F4.0 VS2015中的字符串中获取一个有区别的联合类型。我的代码如下所示:

type FooOrBar =Foo | Bar
let FooOrBarFromString str =
    match str with 
    | "Foo" -> Foo
    | "Bar" -> Bar
    | _ -> raise (System.ArgumentException("Invalid input"))
问题是,如果触发默认条件并引发异常,则参数异常将包装在System.TypeInitializationException中。例:

[<EntryPoint>]
let main argv = 
    let result = FooOrBarFromString "baz"

An unhandled exception of type 'System.TypeInitializationException' occurred in Project.exe
使事情进一步复杂化的是,VS2015调试器随后阻塞并显示源代码不可用。只有在局部视图中检查内部异常,我才能看到发生了什么


有没有更好的方法来设置它,这样输入数据中的错误就不会使调试变得非常痛苦?

无法重现。我正在按预期获取System.ArgumentException无效输入。VS 2015您发布的代码甚至没有编译,因为它缺少main的int返回值。如果添加此项,程序将按预期运行,也就是说,它将抛出System.ArgumentException。你需要展示更多的代码,让我们重现这个问题。