简体   繁体   中英

Handling and printing exceptions with SML

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?

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

- (hd ([]: string list)) handle e => exnMessage e;
val it = "Empty" : string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM