如何定义如下异常?
exception CustomExn<'TMessage> of 'TMessage list
最佳答案
也许您可以仅继承System.Exception?
type CustomExn<'TMessage> (message:'TMessage list) =
inherit System.Exception ()
let test =
try
raise (CustomExn["string"] )
with
| :? CustomExn<string> -> "CustomExn of string"
| :? CustomExn<int> -> "CustomExn of int"
| _ -> "Everything else"
关于generics - 如何在F#中声明通用异常类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49974736/