// define custom exception
exception EqualityError of string
let divide x y =
try
try
// ArgumentException
if x = 0
then invalidArg "x can't be zero."
// FailureException
if y = 0
then failwith "y can't be zero."
// custom Exception
if x = y
then raise (EqualityError "equal") // 'raise' throws exception
x / y
with
| :? ArgumentException -> printfn "Error was %s" message
| Failure message -> printfn "Error was %s" message
| EqualityError message -> printfn "Error was %s" message
finally
printfn "finally"