The AutoCADET's Guide to Visual LISP: Optimize and Customize Your AutoCAD Design Environment

While talking about debugging, it is a good time to bring up the subject of how a program can gracefully recover from an error. Even though you may have tested your program thoroughly, errors will occur. You need to set up a path for the system to follow when a problem occurs in the evaluation of your application. To do this, you use the *ERROR* symbol as a function in your program code.
Visual LISP starts the *ERROR* function when an error occurs in the evaluation of the code. The type of error is supplied as a string argument to the function. You have the opportunity to save your global variables from the local variables because the function is running within the scope of the function that caused the error. To save values stored in local variables, simply use SETQ to move them to global variable names. When doing this, use great care because the error trap has been tripped once and won't be tripped again even if an error occurs in your recovery operations.
When programming an error-recovery trap, do not try to communicate with the operator using input statements. Instead, save the variables you want to save, restore any system variables you may have changed, and return control to the system. You may want to send a message on exit telling the operator what went wrong or how to restart your application.
An example of an error trap is presented in Listing...