Skip to content
This repository has been archived by the owner on Nov 14, 2020. It is now read-only.

try/catch/finally and throw #4

Open
alandipert opened this issue Nov 7, 2013 · 0 comments
Open

try/catch/finally and throw #4

alandipert opened this issue Nov 7, 2013 · 0 comments
Milestone

Comments

@alandipert
Copy link
Owner

Non-local control transfer in the form of exceptions is a feature generally expected by most programmers in any high-level language. Non-local control transfer is useful because it prevents programmers from having to explicitly thread error handling functions through code. The fact try handlers are dynamically bound is useful because it allows programmers to catch exceptions in code they did not write.

I propose the addition of an exceptions system to gherkin that follows mostly from Clojure/JVM and a little from MacLisp/Common Lisp - the main difference between them being that catch tags in Common Lisp are not classes, but can be any object.

This hybrid systems allows us to:

  • provide an exception mechanism without necessarily implementing user-defined types or heirarchies
  • admit user-defined types as catch tags, if we implement them, without breaking existing code

throw

(throw <tag-expr> <result-expr?>)
  • <tag-expr> is evaluated, and when throw is called, the corresponding try handler with the dynamically-nearest, = <tag-expr> is invoked.
  • <result-expr?> is an optional expression that defaults to nil. It is evaluated at throw-time and passed to the dynamically-nearest try handler and bound to <result-form-name>.

catch

(try <exprs> <catch-clause> <finally-clause?>)
  • <exprs> are evaluated, and if now exceptions are thrown, the value of the last is returned.
  • <catch-clause> is (catch <tag-expr> <result-expr-name> <catch-exprs>). If an exception with a matching <tag-expr> is thrown inside <exprs>, <result-expr-name> is bound to the throw expression's <result-expr?> and <catch-exprs> are evaluated.
  • <finally-clause?> is optional and of the format (finaly <finaly-exprs>). Before returning, normally or abnormally, any finally exprs will be evaluated for their side effects.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant