3

Often times I need to debug code wrapped in the BODYFORM of condition-case; however, the debugger is suppressed even though I have debug-on-error set to t. The doc-string states that we can add debug to the list of handlers, but I didn't find a good example by Googling of how this might be accomplished. Modifying the code of something that I am trying to debug to add a handler seems rather inefficient.

Is there an approach to force condition-case to always generate a debugging message without modifying the section of code that I am trying to debug? If not, then an explanation why along with a sample of how to use debug as a handler would be an acceptable answer.

lawlist
  • 18,826
  • 5
  • 37
  • 118

1 Answers1

4

Try using condition-case-unless-debug instead of condition-case.

You should be able to M-x debug-on-entry either foo or bar in this context:

(defun foo ()
  (condition-case-unless-debug nil
      (bar)
    (error nil)))

(defun bar ()
  (message "Cuckoo!")
  (pp-eval-expression '(cons 42 49)))

Note that condition-case-unless-debug just does this:

(macroexpand '(condition-case-unless-debug nil (bar) (error nil)))

gives

(condition-case nil
    (bar)
  ((debug error)
   nil))
Drew
  • 75,699
  • 9
  • 109
  • 225