bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#57195: 28.1.90; Can error backtrace be preserved upon intercepting w


From: Ihor Radchenko
Subject: bug#57195: 28.1.90; Can error backtrace be preserved upon intercepting with `condition-case'?
Date: Sun, 14 Aug 2022 11:49:04 +0800

Consider the following functions:

(defun my/err ()
  (let ((x 0))
    (/ 2 x)))

(defun my/interc ()
  (condition-case err
      (my/err)
    (arith-error
     (backtrace-revert)
     (error "`my/err' signalled an error. Check out Troubleshooting section of 
the manual. (%S)" err))))

`my/interc' function calls `my/err', but wants to provide a more useful
error message. This can obviously be done using `condition-case'.

However, when one tries to run M-: (my/interc), the following backtrace
will appear:

Debugger entered--Lisp error: (error "My custom error: (arith-error)")
  (error "My custom error: %S" (arith-error))
  (condition-case err (my/err) (arith-error (error "My custom error: %S" err)))
  (my/interc)
  (eval-expression (my/interc) nil nil 127)
  (funcall-interactively eval-expression (my/interc) nil nil 127)
  (command-execute eval-expression)

This backtrace is limiting the information up to the `condition-case'
form itself. The deeper levels are not available.

Compare it with the result of M-: (my/err)

Debugger entered--Lisp error: (arith-error)
  (/ 2 0)
  (let ((x 0)) (/ 2 x))
  (my/err)
  (eval-expression (my/err) nil nil 127)
  (funcall-interactively eval-expression (my/err) nil nil 127)
  (command-execute eval-expression)

This backtrace is much more detailed and gives the exact place where the
error happens.

Unfortunately, the second case does not allow to make the error message
more helpful.

Is it possible to display the original backtrace in the intercepted
condition-case?

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92





reply via email to

[Prev in Thread] Current Thread [Next in Thread]