daveliepmann

daveliepmann

Programming Clojure, Third Edition: `assert` throws Error, not Exception (page 206-7)

@alexmiller

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

alexmiller

Author of Programming Clojure, Third Edition

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 Top

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
fynn
This is as much a suggestion as a question, as a note for others. Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New
adamwoolhether
Is there any place where we can discuss the solutions to some of the exercises? I can figure most of them out, but am having trouble with...
New
s2k
Hi all, currently I wonder how the Tailwind colours work (or don’t work). For example, in app/views/layouts/application.html.erb I have...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New

Other popular topics Top

Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
PragmaticBookshelf
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
PragmaticBookshelf
Author Spotlight Erin Dees @undees Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New

Latest in PragProg

View all threads ❯