Package: Emacs Version: 30.0.50 `condition-case` has served us well for the usual error handling needs of common code, but it does not let us capture information about the dynamic context where the error takes place, such as capturing the value of dynamically scoped vars or the backtrace. For that reason, `signal_or_quit` has slowly grown as new needs have come up to run various kinds of debugger-like operations in special cases. The attached patch adds the new special form `handler-bind` which provides a functionality similar to `condition-case` except that the handler is run *before* unwinding the stack. The patch includes a change to `ert.el` to make use of it to capture the backtrace of errors instead of messing with `debugger` and `debug-on-error`, which is fiddly and comes with various problems (such as the fact that it impacts `condition-case-unless-debug`). It's not completely finished but I'm bumping into a question. `ert-tests.el` includes the following test: (ert-deftest ert-test-error-debug () (let ((test (make-ert-test :body (lambda () (error "Error message"))))) (condition-case condition (progn (let ((ert-debug-on-error t)) (ert-run-test test)) (cl-assert nil)) ((error) (cl-assert (equal condition '(error "Error message")) t))))) Until now, this test passes just like that, i.e. without entering the debugger. With the new code, this test does enter the debugger. Can anyone give me a hand figuring out why/how the debugger is not entered with the current code? AFAICT when running the inner `ert-run-test`, we get to `ert--run-test-internal` which sets `debugger` to a function that calls `ert--run-test-debugger` and `debug-on-error` to t, yet when it calls `(error "Error message")` this debugger-function is not called (or at least `ert--run-test-debugger` is not called), which I can't explain. Stefan