Staying Out of Trouble

The irony of picking up a new programming language is that while the goal is to write perfect code, a key skill is to learn how to deal with the myriad of mistakes you’re going to make along the way. To that end, let’s make some mistakes and look at Clojure’s reaction to them.

For example, what happens if we make the classic divide by zero blunder?

 (/ 100 0)

What you will see when you divide by zero depends on the environment in which you are executing your Clojure code. You might see a brief

 ArithmeticException Divide by zero
  clojure.lang.Numbers.divide (Numbers.java:156)

Or you might see this much more extensive message:

 java.lang.ArithmeticException​:​ Divide by zero
 Numbers.java:156 clojure.lang.Numbers.divide ...

Get Getting Clojure 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.