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'...
user avatar
  • 20.3k
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-...
user avatar
  • 21k
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'
user avatar
  • 8,793
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 ...
user avatar
  • 25.3k
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)))...
user avatar
  • 13.6k
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 ...
user avatar
  • 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-...
user avatar
  • 22.4k
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 ...
user avatar
  • 6,963
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 ...
user avatar
  • 159
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.
user avatar
  • 5,510
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 (...
user avatar
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.
user avatar
  • 625
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 ...
user avatar
  • 25.3k
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) (...
user avatar
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 ...
user avatar
  • 69.6k
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-...
user avatar
  • 69.6k
5 votes

What do I do when Emacs is frozen?

It also sometimes helps to abort-recursive-edit with C-].
user avatar
  • 1,831
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'.
user avatar
  • 11.3k
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 ...
user avatar
  • 13.6k
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-...
user avatar
  • 25.3k
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 ...
user avatar
  • 69.6k
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,...
user avatar
  • 227
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 ...
user avatar
  • 2,015
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 ...
user avatar
  • 5,765
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.
user avatar
  • 2,594
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 ...
user avatar
  • 69.6k
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 ...
user avatar
  • 6,681
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 ...
user avatar
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, ...
user avatar
  • 21k

Only top scored, non community-wiki answers of a minimum length are eligible