BTW, that's a pretty old-school way of treating the error handler. Not to mention that the redefined error handler is not even there (presuming you elected to not post it).
Here is the approach many starting using once AutoCAD 2000 was released:
Code:
(defun MyExit (msg)
(cond
((not msg)) ; no error, normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\nError: " msg)))) ; error, display it
;| any other code for needed cleanup |;
(princ))
(defun C:MainCode (/ *Error*) ; localize error handler
(setq *Error* MyExit) ; redefine local error handler
;| rest of the main code |;
(MyExit nil)) ; normal, clean exit
This works because once AutoCAD 2000 came out, when a localized error handler runs, it remains local. Prior to 2000, when a localized error handler ran it would become global, overwriting the original global error handler. That is where the save old, set new, restore old approach came from. There is no need for that any longer.
The other advantage to this later approach is that you need to write the clean code only once. The MyExit function can act in both an error situation or a normal exit, as long as you handle the msg argument as being nil in a normal exit.