- 积分
- 7474
- 明经币
- 个
- 注册时间
- 2006-8-3
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 redcat 于 2011-2-12 12:40 编辑
- ;;;错误处理教程-1
- (defun c:tt1 (/ varlst var_old var_new)
- (defun *error* (inf)
- (setq inf (strcase inf t)) ;将出错信息转换为小写字符串
- (cond
- ((wcmatch inf "*break,*cancel*,*exit*,*取消*") ;|按了<Esc>键出错处理|;
- (princ "\n用户按了<Esc>强制退出\n")
- (mapcar 'setvar varlst var_old)
- )
- (t ;|其余错误处理|;
- (princ (strcat "\n" inf))
- (mapcar 'setvar varlst var_old)
- )
- ) ;_ 结束cond
- (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
- (princ)
- ) ;_ 结束defun
- (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
- (setq varlst '("osmode")
- var_new '(0)
- var_old (mapcar 'getvar varlst)
- ) ;_ 结束setq
- (mapcar 'setvar varlst var_new)
- (princ "\n按<Esc>强制退出, <空格>/<Enter>/<右键>错误...")
- (rtos (getreal "\n请输入实数:"));出错后转到内部自定义的*error*函数
- (mapcar 'setvar varlst var_old)
- (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
- (princ)
- ) ;_ 结束defun
- ;;;错误处理教程-2
- (defun c:tt2 (/ err inf varlst var_old var_new)
- (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
- (setq err (vl-catch-all-apply
- '(lambda ()
- (setq varlst '("osmode")
- var_new '(0)
- var_old (mapcar 'getvar varlst)
- ) ;_ 结束setq
- (mapcar 'setvar varlst var_new)
- (princ "\n按<Esc>强制退出, <空格>/<Enter>/<右键>错误...")
- (rtos (getreal "\n请输入实数:"))
- ) ;_ 结束lambda
- ) ;_ 结束vl-catch-all-apply
- ) ;_ 结束setq
- (if (vl-catch-all-error-p err)
- (progn ;|出错处理|;
- (setq inf (strcase (vl-catch-all-error-message err) t)) ;将出错信息转换为小写字符串
- (cond ((wcmatch inf "*break,*cancel*,*exit*,*取消*") ;|按了<Esc>键出错处理|;
- (princ "\n用户按了<Esc>强制退出\n")
- (mapcar 'setvar varlst var_old)
- (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
- )
- (t ;|其余错误处理|;
- (princ (strcat "\n" inf))
- (mapcar 'setvar varlst var_old)
- (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
- )
- ) ;_ 结束cond
- (princ)
- ) ;_ 结束progn
- (progn ;|程序正常运行完毕的处理|;
- (princ "\n")
- (mapcar 'setvar varlst var_old)
- (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
- (princ)
- ) ;_ 结束progn
- ) ;_ 结束if
- ) ;_ 结束defun
|
|