I have this newbie question: in Standard ML, how can you catch an exception like "Error: unbound variable or constructor: foo"?
I tried to do this with the following program:
(foo())
handle Error msg => ();
But REPL complains: "Error: non-constructor applied to argument in pattern: Error"
Thanks in advance.
First of all it's handle Error => ...
(or handle error => ...
or handle TheSpecificExceptionIWantToCatch => ...
), not handle Error msg => ...
. You can only write handle Foo msg => ...
if Foo
is a constructor with one argument, which, as the error message suggests, Error
is not.
Secondly "unbound variable" is a compilation error, not an exception, so it can't be caught.