How to throw and test errors in Emacs Lisp?
September 26, 2023
(defun foo (x)
"Return x. If x < 0, throw an error."
(if (< x 0)
(error "%s is negative" x)
x))
(ert-deftest foo-test ()
(should (= (foo 10) 10))
(should-error (foo -1)))
(foo -1)