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 ...

Get Mastering Clojure Macros now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.