Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alexknauth/try-catch-finally

A racket macro for catching exceptions and running teardown operations.
https://github.com/alexknauth/try-catch-finally

Last synced: about 1 month ago
JSON representation

A racket macro for catching exceptions and running teardown operations.

Awesome Lists containing this project

README

        

try-catch-finally
=================
A macro for catching exceptions and running teardown operations.

Documentation: https://docs.racket-lang.org/try-catch-finally/index.html

```scheme
(try
body ...+
catch-clause ...
maybe-finally-clause)

catch-clause = (catch pred => handler)
| (catch (pred id) handler-body ...+)
| (catch (id) handler-body ...+)
| (catch _ handler-body ...+)

maybe-finally-clause =
| (finally post-body ...+)
```

Examples:
```scheme
> (try
(raise-syntax-error #f "a syntax error")
(catch (exn:fail:syntax? e)
(displayln "got a syntax error")))
got a syntax error
> (try
(raise-syntax-error #f "a syntax error")
(catch (exn:fail:syntax? e)
(displayln "got a syntax error"))
(catch (exn:fail? e)
(displayln "fallback clause")))
got a syntax error
> (try
(displayln "at")
(finally (displayln "out")))
at
out
> (let/cc up
(try
(displayln "at before")
(up (void))
(displayln "at after")
(finally (displayln "out"))))
at before
out
```