Error formatting macro: pagetree: java.lang.NullPointerException
Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current  |   View Page History

Clojure and ClojureScript allow the user to handle platform exceptions with the 'try special form. This page aims to provide a specification for a cross-platform error handling strategy.


Error handling is highly platform dependent, '(try (catch)) directly dispatches on platform type names. There is no platform-independent catch-all clause.

'try special form has a cascaded 'instanceof dispatch built in, which is reasonable for java because it maps directly to the native try{}catch(E e){}, but adds complexity in ClojureScript, where the native try{}catch(e){} is untyped.

Currently there is no catch-all in clojurescript at all.


This proposal considers a generic design for '(try (catch)) expressions, that can be augmented with platform-dependent error handling.

The design should be backwards-compatible with Clojure and ClojureScript and it should be implementable in every Clojure dialect for platforms that have platform-provided escape continuations (i.e. exceptions).

Rejected alternatives

Former ClojureScript's (try* ..  (catch e# ..))

Platform-Error handling should have a basic form that's the same on all platforms. Even if Clojure gained try*, one still couln't mix catching specific exceptions with catch-all.

Proposed solution

In addition to the regular type-dispatched catch clauses, try forms will accept a '(catch* e# ..) clause, that catches all throwables in a platform-independent manner.

The platform-independent subset of 'try forms would essentially amount to '(try .. (catch* e# ..)).

Delivering a more sophisticated mechanism than catch-all, even though included in the scope, is not proposed, because it can be easily implemented as library code.