2

I have a code that looks quite like:

ignore
  (f ())
  handle
    AssertionError msg         => (print ("assertion error: " ^ msg ^ "\n"); ())
    | _ (* other exceptions *) => (print ("exception raised\n"); ())

But I need to print the generic exception message (with exnMessage?).

How do I catch the _ exception in order to get and print its message?

1 Answers1

3

Match the exception with a name instead of _ and use exnMessage:

- (hd ([]: string list)) handle e => exnMessage e;
val it = "Empty" : string
molbdnilo
  • 64,751
  • 3
  • 43
  • 82