0

Assume that I have two functions, say function1 and function2. I would like to execute function2 only if there is some error during the execution of function1. So far, I have tried the below code

(ignore-errors (function1) (function2))

This executes function2 if there is some error with function1, but it executes function2 if there is no error with function1 as well.

How to correct the code?

3

Read about condition-case in C-hig (elisp)Handling Errors

(condition-case nil
    (function1)
  (error (function2)))
3
  • Thank you, but it seems not working if I do not miss something. If (function1) is (call-interactively 'ispell-word), (function2) is (message "hello") and ispell default language is English and I execute the above function on the word Ελληνικά since there is an error saying Error checking word ΕΛΛΗΝΙΚΆ using hunspell.exe with default dictionary it is expected that to see hello but it is not the case. – Name Jul 9 '20 at 12:15
  • At a guess, ispell-word is handling its own errors and not re-signaling it for any outer handlers to see. In which case there simply isn't any error for you to handle, so far as your code is concerned. – phils Jul 9 '20 at 13:16
  • Thank you, it does not solve my problem with ispell, but it literally answer the question. – Name Jul 11 '20 at 9:27

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.