
daveliepmann
Programming Clojure, Third Edition: `assert` throws Error, not Exception (page 206-7)
On page 206 to 207, my copy of Programming Clojure, Third Edition asserts the following:
assert
tests an expression and raises an exception if it’s not logically true:(assert (= 1 1)) -> nil (assert (= 1 2)) -> java.lang.Exception: Assert failed: (= 1 2)
This matches the assert
docstring:
Evaluates expr and throws an exception if it does not evaluate to
logical true.
Unfortunately, it’s not so. assert
raises an AssertionError, which is not an Exception. Reference Clojure source, ask Clojure question, JIRA ticket, REPL output:
$ clj
Clojure 1.11.1
user=> (assert (= 1 1))
nil
user=> (assert (= 1 2))
Execution error (AssertionError) at user/eval138 (REPL:1).
Assert failed: (= 1 2)
user=> (set! *assert* false)
false
user=> (assert (= 1 2))
nil
Perhaps the book’s REPL output predates this 2009 commit?
Marked As Solved

alexmiller
The book and docstring say it “throws an exception” (a Java and Clojure language mechanism), not “throws Exception” (a specific Java class), so I think the statements are correct regardless.
Generally, the docstrings are careful about what they commit to, and there is no commitment here to a specific class.
Popular Prag Prog topics










Other popular topics









Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /haskell
- /java
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /centos
- /ash
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /textmate
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /julia
- /c
- /slackware
- /neovim