mirror of
https://github.com/unisonweb/unison.git
synced 2024-10-26 02:55:19 +03:00
75c228f4e1
The bulk of this updates transcripts to put spaces around the language name in code blocks. E.g., ```` markdown ```ucm:hide ```` becomes ```` markdown ``` ucm :hide ```` This corresponds to https://share.unison-lang.org/@unison/website/contributions/11, which updates the docs in the same way. This is effectively a fix for #5214, but that issue also has good recommendations for future changes to info strings, so I don’t know that it should be closed.
46 lines
863 B
Markdown
46 lines
863 B
Markdown
A simple transcript to test the use of exceptions that bubble to the top level.
|
|
|
|
``` ucm :hide
|
|
scratch/main> builtins.merge
|
|
```
|
|
|
|
FYI, here are the `Exception` and `Failure` types:
|
|
|
|
``` ucm
|
|
scratch/main> view Exception Failure
|
|
```
|
|
|
|
Here's a sample program just to verify that the typechecker allows `run` to throw exceptions:
|
|
|
|
``` unison
|
|
use builtin IO Exception Test.Result
|
|
|
|
main : '{IO, Exception} ()
|
|
main _ = ()
|
|
|
|
mytest : '{IO, Exception} [Test.Result]
|
|
mytest _ = [Ok "Great"]
|
|
```
|
|
|
|
``` ucm
|
|
scratch/main> run main
|
|
scratch/main> add
|
|
scratch/main> io.test mytest
|
|
```
|
|
|
|
Now a test to show the handling of uncaught exceptions:
|
|
|
|
``` unison
|
|
main2 = '(error "oh noes!" ())
|
|
|
|
error : Text -> a ->{Exception} x
|
|
error msg a =
|
|
builtin.Exception.raise (Failure (typeLink RuntimeError) msg (Any a))
|
|
|
|
unique type RuntimeError =
|
|
```
|
|
|
|
``` ucm :error
|
|
scratch/main> run main2
|
|
```
|