Error Handling
If an error occurs when an expression is evaluated, Lisp prints an error message. However, in many cases, printing only the system’s error message is not sufficient. Often, you also want to make sure that certain states and modes are restored when a function is cancelled.
The *error* function lets you to define your own error handler. The function has only one argument: a string to which the error message text of the system is passed. Instead of printing the message, the Lisp Interpreter executes your error handler. Within your error handler you can evaluate the message and perform functions to restore the settings of modified system variables, set states back as they were before your routine was performed, etc.
Using the expression (setq *error* nil) restores the default error handler of the system.
Example
The following is an example for a function definition for error handling:
(defun *error* (msg)
(if (= msg "User break")
(setvar "OSMODE" osmode_save)
(progn
(princ "The following error occurred: ")
(princ msg)
(terpri)
)
)
(setq *error* nil)
(princ)
)