捕获所有异常

异常处理

(defn throw-when-nil-or-empty [coll]
  (cond
    (nil? coll) (throw (IllegalArgumentException. "is nil"))
    (empty? coll) (throw (IllegalStateException. "is empty"))))

;; Exception 捕获任何异常,
;; Throwable 还能捕获错误(OutOfMemoryError 等)
(try
  (throw-when-nil-or-empty nil)
  (catch Exception e
    (println "Error happened" (.getSimpleName (class e)))))