【发布时间】:2020-09-05 15:14:07
【问题描述】:
我有一个函数,我需要在以下 sn-p 中模式匹配(不是try...with)异常与类型测试:
module Error =
type Codes =
| InvalidUser = 0
| InvalidEmail = 1
exception AppException of Codes
let errorHandler (e: exn) =
// This doesn't work
match e with
| :? AppException as err(code) ->
code.ToString()
| _ -> e.Message
errorHandler 是一个通用函数,用于捕获 AppExeption 以及应用程序中的其他未处理异常。
如何将模式匹配与 Type Test 结合使用并解构/检索code 作为AppException 的一部分?
【问题讨论】:
标签: f#