The simple declaration of exceptions using exception
limited in many ways. If you want to use other functions of the standard .NET exceptions (i.e., an internal exception), you can declare the exception as a class:
open System type FooException(message:string, innerException:Exception) = inherit Exception(message, innerException)
You can also provide overloaded constructors, for example, if you want to use null
as the default for InnerException
. An exception can be raised as a regular .NET exception using raise
:
raise (new FooException(message, e))
source share