ryoakg
6/23/2016 - 5:29 AM

catching-compile-time-exception.clj

(defmacro cannot-compile []
  `(. "some object" noSuchMethod))


(try
  (cannot-compile)
  (catch clojure.lang.Compiler$CompilerException e
    (println "catch CompilerException!")))
;; java.lang.IllegalArgumentException: No matching field found: noSuchMethod for class java.lang.String


(defmacro evaluate-at-expanding-macros []
  (try
    (cannot-compile)
    (catch clojure.lang.Compiler$CompilerException e
      (println "catch CompilerException!"))))

(evaluate-at-expanding-macros)
;; java.lang.IllegalArgumentException: No matching field found: noSuchMethod for class java.lang.String


(try
  (eval `(. "some object" noSuchMethod))
  (catch Exception e
    (println "caught!")))
;; caught!!