From: vnestr@netvision.net.il (Vladimir Nesterovsky) Newsgroups: autodesk.autocad.customization Subject: Re: Error Handling Date: Sat, 22 Nov 1997 23:08:04 GMT -- edited (Apr 06) to account for some renaming in the error.lsp file -- (apart from it looking a bit bogus to me right now, w.r.t. OQ actually, -- but as a general error handling framework it's very useful and convinient). Mark -- I assume you're talking about LISP variables, not "setvars", so this may be considered as a desired behavior actually, as it lets you examine your variables' values after the error and helps you debug your program. Of course if you have Vital LISP then you have a much better debugger! :) But if you want your variables reset on error (after you've finished your debugging), that's fine. If you were referring to sysvars, then too it's better to reset them back to their original state when your program finishes. This can be accomplished by a couple of standardized error handling functions that you use throughout all your programs. I'm posting ERROR.LSP file to my home page, which allows you to do some standardized calls. All functions are prefixed by 'vn-' to avoid name collisions. Here's an excerpt from this file: Global variables used: *vn_hookfuncs* -- an undo list *vn_sysvars* -- saved sysvars *vn_olderr* -- previous error handler Functions defined: vn-push -- general utility -- push first element vn-pop -- general utility -- pop first element from vn-errpush -- plug into error handler vn-errpop -- remove first action from error handler vn-errpopdo -- pop it and DO vn-push-sysvars -- change sysvar and save its value vn-pop-sysvars -- restore a number of sysvars vn-pop-all-sysvars -- restore all sysvars vn-on-error -- a standardized error handler vn-errbegin -- start error handling vn-errend -- stop error handling You can use these functions like this: (defun your-function ( arguments ) (vn-errbegin) (vn-push-sysvars '( ("cmdecho" 0) ; change and save ("clayer") ; just save it ("aunits" 3) ("ucsfollow" 0) )) ; etc. (command "._ucs" "_w") ; set UCS to WORLD for example (vn-errpush '( (command "._ucs" "_p") (princ "\n UCS restored!") )) ; make it to be undone automatically on error ;; your code here ;; ...... (vn-errpopdo) ; undo the UCS WORLD (vn-pop-sysvars 2) ; restore last two sysvars ;; do some more... (vn-errend) ; undo the rest of plug-in functions and ) ; restore all sysvars. So finally, if you want to reset your LISP variables on error, you can do it like this: (defun your-function ( arg1 arg2 arg3 / arg4 ) (vn-errbegin) ;; ...... (vn-errpush '( (setq arg1 nil arg2 nil arg nil) (Setq arg4 nil) )) ;; ........ (vn-errpop) ; remove it from undo list w/out doing it (vn-errend)) Of course this won't restore their previous values; I don't think you can do this from within your-function, as these variables are already set to their new values on entry to your-function by LISP interpreter, so to restore them you'll need to make a call to vn-errpush _before_ calling your-function. Cheers, ------- Original message: ------- On Wed, 19 Nov 1997 11:08:42 -0500, - Mark Walker wrote in autodesk.autocad.customization: >Ok, quick question. I have several different lisp routines that set and >reset variables upon exicution. But, if the user cancels out of the >routine before it is finished, then the variables do not get reset. >Now, I know there is some method of handling this, but I have not been >able to get any good examples to go by. Could anyone pls give me a >source to look at for refernece, or just tell me how to do it? > >Mark Walker >Information System Specialist >Southern Pan Services >NewMWalker@aol.com --- Live long and prosper :) Vlad http://www.netvision.net.il/php/vnestr