My Clojure code has some java-interop with a method that throws multiple exceptions. I wish to deal with each individual of them. According to Clojure documentation:
(try expr* catch-clause* finally-clause?)
catch-clause -> (catch classname name expr*)
it has no mention of catching multiple exceptions. Is it possible to do so in Clojure?
Thank you!
It’s the same as in Java, you can declare several
catchexpressions one after the other, and they’ll get matched in the same order they were declared – firstException1, if it doesn’t match thenException2and so on, and thefinallypart will always be executed.In fact, this is specified in the documentation,
(try expr* catch-clause* finally-clause?)means that you can have “zero or more expressions”, “zero or more catch clauses” and “zero or one finally clauses” as part of atryexpression.