all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#57195: 28.1.90; Can error backtrace be preserved upon intercepting with `condition-case'?
@ 2022-08-14  3:49 Ihor Radchenko
  2022-08-15  7:18 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Ihor Radchenko @ 2022-08-14  3:49 UTC (permalink / raw)
  To: 57195

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#57195: 28.1.90; Can error backtrace be preserved upon intercepting with `condition-case'?
  2022-08-14  3:49 bug#57195: 28.1.90; Can error backtrace be preserved upon intercepting with `condition-case'? Ihor Radchenko
@ 2022-08-15  7:18 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2022-08-15  7:18 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: 57195

Ihor Radchenko <yantar92@gmail.com> writes:

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

I don't think that's possible, so that's why condition-case-unless-debug
exists.






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-15  7:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-14  3:49 bug#57195: 28.1.90; Can error backtrace be preserved upon intercepting with `condition-case'? Ihor Radchenko
2022-08-15  7:18 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.