unison/unison-src/transcripts/top-level-exceptions.md
2024-06-25 11:11:07 -07:00

856 B

A simple transcript to test the use of exceptions that bubble to the top level.

scratch/main> builtins.merge

FYI, here are the Exception and Failure types:

scratch/main> view Exception Failure

Here's a sample program just to verify that the typechecker allows run to throw exceptions:

use builtin IO Exception Test.Result

main : '{IO, Exception} ()
main _ = ()

mytest : '{IO, Exception} [Test.Result]
mytest _ = [Ok "Great"]
scratch/main> run main
scratch/main> add
scratch/main> io.test mytest

Now a test to show the handling of uncaught exceptions:

main2 = '(error "oh noes!" ())

error : Text -> a ->{Exception} x
error msg a =
  builtin.Exception.raise (Failure (typeLink RuntimeError) msg (Any a))

unique type RuntimeError =
scratch/main> run main2