68
votes
Accepted
What do I do when Emacs is frozen?
When C-g doesn't work, you can sometimes get control back with:
pkill -SIGUSR2 emacs
As @Archenoth points out, sending the SIGUSR2 signal to Emacs turns on debug-on-quit. This can be useful, but you'...
19
votes
Accepted
Show line number on error
Emacs provides a good amount of debugging facilities including M-x toggle-debug-on-error, M-x toggle-debug-on-quit, debug on signal (which can be used by sending USR2 to Emacs from outside), debug-on-...
14
votes
Rethrowing an error in Emacs Lisp
You're looking for signal:
(condition-case err
(call-function)
(error
(cleanup)
(signal (car err) (cdr err)))) ; reraise `err'
11
votes
Accepted
Rethrowing an error in Emacs Lisp
BTW, an alternative option can be something like:
(let ((error t))
(unwind-protect
(prog1 (call-function)
(setq error nil))
(when error (cleanup))))
The advantage is that you ...
10
votes
How to call another function, if one function gives an error message
No need to read *Messages*. Here's how error handling works in Elisp:
(defun bar ()
(error "asdf"))
(defun foo ()
(condition-case e
(bar)
(error
(message "Caught an error: %S" e)))...
9
votes
Accepted
How to gracefully handle errors in init file
Two options, neither of which are perfect, come to mind. First, you could wrap most of your early initialization code (ie, before it gets to your customizations) in (ignore-errors ...). If there are ...

Dan♦
- 31.1k
8
votes
How to gracefully handle errors in init file
@Dan described well how you can turn errors into messages. You can
also do whatever you want with errors by using
condition-case.
Yet another option is to use
unwind-protect.
I’ll stick to condition-...
7
votes
Accepted
What is the difference between the error handler in condition-case and the error function
The docstring for condition-case (C-h f condition-case) says:
condition-case is a special form in `C source code'.
(condition-case VAR BODYFORM &rest HANDLERS)
Regain control when an ...
6
votes
Show line number on error
Maybe because it's 2018 now, but in my case,
I only had to turn on debugging like wasamasa suggested:
M-x toggle-debug-on-error
After this, M-x eval-buffer on my faulty Elisp file
gave context ...
6
votes
Accepted
Capturing stderr of subprocesses
This is fixed in Emacs 25, where you can use the make-process function with the :stderr argument. I don't think there's anything suitable in Emacs 24.
6
votes
Accepted
Emacs flickers when I run certain commands (gif screencast included)
It looks like visible-bell mode is enabled. This means that whenever an Emacs command rings a bell (i.e. fails in some way), it will try to flash the screen.
You should be able to turn it off with (...
6
votes
Accepted
Symbol's function definition is void: insert-string
See this issue. This problem should be fixed in the next release.
Quick fix:
Change the function insert-string to insert in ~/.emacs.d/core/core-spacemacs-buffer.el, and everything works well.
5
votes
Accepted
How to condition-case Lisp nesting exceeds `max-lisp-eval-depth'?
Try:
(condition-case err
(potentially-too-recursive-function)
(error (message "error=%S, data=%S" (car err) (cdr err))))
This will not only catch the error but will additionally emit a message ...
5
votes
Accepted
How to call another function, if one function gives an error message
The error in question is thrown with user-error, not simply echoed with message.
In your particular case testing the return value of evil-get-marker should work also:
(if (evil-get-marker ?8)
(...
5
votes
Error in post-command-hook during org-agenda-todo
debug-on-error, and more generally the debugger, are not available for errors raised from post-command-hook (for example, to prevent runaway recursion).
What you can do is what programmers have done ...
5
votes
How to prevent Emacs from opening error buffer
Not exactly sure what the context is or what you mean.
If by "open a window with an error" and "opening error buffer" you mean opening the debugger in buffer *Backtrace*, then set variable debug-on-...
5
votes
5
votes
Accepted
When I (byte-compile-file "my-package.el"), can I treat warnings as errors?
The documentation for the customisable variable byte-compile-error-on-warn says:
If true, the byte-compiler reports warnings with `error'.
5
votes
Accepted
Couldn't make condition-case work
Your error symbol test-signal is not defined. C-h f signal says:
An error symbol is a symbol with an error-conditions property
that is a list of condition names.
Let's check this for some ...
4
votes
Accepted
define-error for older Emacs?
That looks fine, except that I'd use (fboundp 'define-error) instead of testing the version number.
Until Emacs-24.3 what was used instead were manual calls to put as in:
(put 'foo-error 'error-...
4
votes
Accepted
Standard way of reporting user errors to user?
You can use whatever you think is most appropriate for your context. There is no "right" way for all contexts.
message does not prevent continued processing of the current command. If you want to be ...
4
votes
Orgmode table error - shrunk field?
I experienced the same (invalid-function org-table-with-shrunk-field) issue and resolved it with the following process, gleaned from the comments:
confirm the source of the issue with M-x org-version,...
4
votes
Accepted
use search-forward to determine bound of another search-forward
When searching, Emacs starts from the current point. Also, when it searches, it moves the point forward until it finds a match (or reaches the end of the buffer).
After your first search, the point is ...
3
votes
How to call another function, if one function gives an error message
If the function your are calling really echoes a message, you can use (current-message).
Return the string currently displayed in the echo area, or nil if
none.
Of course, it would be better to ...
3
votes
Accepted
How to abort saving in a before-save-hook function?
Try using one of the hooks write-file-functions or write-contents-functions instead. Your hook function can signal an error or just return non-nil, and in either case it will abort the save.
3
votes
Accepted
Cryptic startup error messages
Your init file needs to load the code that defines elpy-mode before it does the code that uses elpy-mode (i.e., before the (if (require 'flycheck)...)).
You need to add (require 'elpy) before that if ...
3
votes
Accepted
How do I catch signals?
You must define the symbol as an error first:
(define-error 'my-error "Custom error")
(condition-case err
(signal 'my-error 'my-data)
(my-error (message "data: %S" err)))
Evaluating this form ...
3
votes
File mode specification error: How to find syntax problem: Missing :END: line in org-mode properties?
This appears to be coming from the function org-flag-drawer.
Use C-h f to find where this function is defined, and modify it to also give the buffer name:
(defun org-flag-drawer (flag)
"When FLAG ...
3
votes
Accepted
Is the unwind-protect's clean form always evaluated?
This is a classic case where reading the docs gives you the answer immediately:
unwind-protect is a special form in ‘C source code’.
(unwind-protect BODYFORM UNWINDFORMS...)
Do BODYFORM, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
error-handling × 68debugging × 10
init-file × 6
org-mode × 5
elisp × 4
key-bindings × 3
package × 3
microsoft-windows × 3
process × 3
echo-area × 3
warning × 3
spacemacs × 2
latex × 2
auctex × 2
functions × 2
message × 2
subprocess × 2
edebug × 2
quitting × 2
conditionals × 2
backtrace × 2
osx × 1
hooks × 1
shell × 1
frames × 1