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.

  • Have you tried using condition-case-unless-debug instead of condition-case? – Drew Feb 5 '17 at 17:31
  • @Drew -- thank you for the suggestion -- I'll give that a try this morning. – lawlist Feb 5 '17 at 17:32
  • FYI, setting debug-on-signal can be useful for this too (although it's sometimes a bit too much). – npostavs Feb 6 '17 at 13:46
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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.