Exception handling

(defn sell [cars]
  (when (empty? cars)
    ;; ex-info is the Clojure way: an exception carrying DATA,
    ;; not only a text message
    (throw (ex-info "No cars for sale" {:cars-count (count cars)}))))

(try
  (sell [])
  (catch Exception e
    (println (ex-message e))
    ;; (ex-message e) is "No cars for sale"
    (println "data is" (ex-data e))))

;; a plain Java exception works too
(try
  (throw (IllegalStateException. "empty garage"))
  (catch Exception e
    (println (ex-message e))))