I have a simple custom exception like the following, but I don’t like using the Throw function, and I really don’t like having the Throw and Throw2 functions. Is there a more elegant way to do this? Is there a way to throw MyError or Error directly without an intermediate function?
#light module Utilities.MyException type MyError(code : int, msg : string) = member e.Msg = msg member e.Code = code new (msg : string) = MyError(0, msg) exception Error of MyError let public Throw (msg : string) = let err = new MyError(msg) raise (Error err) let public Throw2 (code : int) (msg : string) = let err = new MyError(code, msg) raise (Error err)
I use it as the following, but I would like to use one of the options that did not work
Throw(System.String.Format("Could not parse boolean value '{0}'", key))
source share