Browse Learn Clojure Foundations as a Java Developer

Java Exceptions in Clojure

Catch, throw, wrap, and translate JVM exceptions from Clojure while using ex-info and ex-data for context that is easier to inspect and test.

Java exceptions behave the same way in Clojure: they are JVM throwables. The syntax is just different.

1(try
2  (slurp "missing.txt")
3  (catch java.io.FileNotFoundException e
4    (throw (ex-info "File missing" {:path "missing.txt"} e))))

The Clojure pattern that Java developers usually learn next is ex-info + ex-data: wrap a failure with a message and a small data map that callers can inspect. This section focuses on writing exception handling that is explicit, testable, and not scattered across your core logic.

In this section

  • Catching Java Exceptions in Clojure
    Use try, catch, and finally around Java calls, catch the narrowest useful Throwable type, and keep recovery logic close to the interop boundary.
  • Throwing Exceptions from Clojure
    Throw JVM exceptions from Clojure when Java callers require them, but prefer ex-info with structured ex-data when the error is meant for Clojure code.
  • Translating Exceptions at Java Boundaries
    Translate Java exceptions into Clojure-friendly ex-info data, or translate Clojure failures into Java-visible exception types when an API contract requires it.
Revised on Saturday, May 23, 2026