Exceptions

spork-lang 0.6.0

Catch, throw, finalize, and assert with Python exception values.

Spork uses Python exception objects and propagation rules. The forms on this page add expression-oriented handling, cleanup, assertions, and explicit raising without introducing a separate exception hierarchy.

Try / Catch / Finally#

(try
  (risky-operation)
  (catch ValueError e
    (print "Value error:" e)
    :error)
  (catch Exception e
    (print "General error:" e)
    :error)
  (finally
    (cleanup)))

Throw#

(throw (ValueError "invalid input"))

Assert#

The prelude assert macro raises AssertionError when its test is falsy. See assert in the standard library reference for usage.