O'Reilly logo

Mastering Clojure Macros by Colin Jones

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Error Handling in Macros

Most macros, like our pattern matching example in the previous section, have very specific sets of input that they accept, and will throw strange-looking errors when those input expectations aren’t satisfied. For instance, if we didn’t realize that snore.match only handled vectors as input, we might try to match against a keyword, which would give us this error:

language_features/error_handling_1.clj
 
(match :foo
 
:oh ​"hi"
 
:foo ​"bar"
 
:else ​"else"​)
 
UnsupportedOperationException count not supported on this type: Keyword
 
clojure.lang.RT.countFrom (RT.java:556)
 
java.lang.UnsupportedOperationException: count not supported on this type: Keyword
 
RT.java:556 clojure.lang.RT.countFrom
 
RT.java:530 clojure.lang.RT.count ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required