In my initialization file, I have got:

(require-package 'clips-mode)

The thing is that, lately, this package fails to be loaded sometimes (it's already downloaded but I guess it fails when it tries to check for new versions of the package), and when this happens, the initialization file stops reading and subsequent sentences are not read.

I'd like to know if there are a way to ignore errors and keep going even if this specific require-package sentence fails, so the rest of the initialization code is applied anyway.

  1. You can wrap that in ignore-errors, to ignore any error evaluating it might raise:

    (ignore-errors (require-package 'clips-mode))
  2. If you want to ignore only particular errors then you can instead wrap it with condition-case:

    condition-case is a special form in C source code.

    (condition-case VAR BODYFORM &rest HANDLERS)

    Regain control when an error is signaled.

    Executes BODYFORM and returns its value if no error happens. Each element of HANDLERS looks like (CONDITION-NAME BODY...) where the BODY is made of Lisp expressions.

    A handler is applicable to an error if CONDITION-NAME is one of the error’s condition names. If an error happens, the first applicable handler is run.

    The car of a handler may be a list of condition names instead of a single condition name; then it handles all of them. If the special condition name debug is present in this list, it allows another condition in the list to run the debugger if debug-on-error and the other usual mechanisms says it should (otherwise, condition-case suppresses the debugger).

    When a handler handles an error, control returns to the ‘condition-case’ and it executes the handler’s BODY... with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error. (If VAR is nil, the handler can’t access that information.) Then the value of the last BODY form is returned from the condition-case expression.

    See also the function signal for more info.

  3. Why not try to find out what error is raised and why? Set debug-on-error to t before that require-package gets invoked (without using any ignore-errors or condition-case), and look at the resulting debugger backtrace. It might be better to take care of the cause of such an error, rather than just ignoring it.

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.