Skip to content

Instantly share code, notes, and snippets.

@eiriktsarpalis
Last active August 29, 2015 14:01
Show Gist options
  • Save eiriktsarpalis/8feb78f1f2ee7b6bfd02 to your computer and use it in GitHub Desktop.
Save eiriktsarpalis/8feb78f1f2ee7b6bfd02 to your computer and use it in GitHub Desktop.
failwith
// stackless raise
let inline raise (e : exn) = (# "throw" e : ^T #)
let inline failwith ctor = raise << ctor
let inline failwithf ctor fmt = Printf.ksprintf (raise << ctor) fmt
// 1
exception SomeOtherException of string
with override e.Message = e.Data0
failwithf SomeOtherException "exception %d" 42
// 2
let inline invalidOp msg = new InvalidOperationException(msg)
failwithf invalidOp "Invalid operation %s" "foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment