- 积分
- 30269
- 明经币
- 个
- 注册时间
- 2004-10-24
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 kwok 于 2013-3-31 14:01 编辑
复制了码测试了后提示函数有错,提示:错误: *error* 函数中出错参数类型错误: (or stringp symbolp): nil
俺弄不明白,帮看看为什么?
下面是G版的出错处理源码.
;;例3:自定义通用错误处理初始化函数
;;(gxl-error-init syslst) 初始化*error*
;;;功能:保存syslst给定的系统变量值,并按表给定的系统变量值设置系统变量
;;; 参数 syslst 系统变量及其设置值列表 例如: '("osmode" 0 "cmdecho" 0 "cecolor" "1")
(vl-load-com)
(defun gxl-error-init1 (syslst fun UndoMode / sysname sysvar)
(setq *olderror* *error*
*Function* fun
*UndoMode* UndoMode
)
(defun *error* (msg / sysname sysvar)
(if (= 2 *UndoMode*)
(progn
(if (= 8 (logand (getvar “undoctl”) 8))
(command “_undo” “_e”)
)
(command “_U”)
)
(progn
(if *sysvarInit*
(while (and (setq sysname (car *sysvarInit*))
(setq sysvar (cadr *sysvarInit*))
)
(setq *sysvarInit* (cddr *sysvarInit*))
(setvar sysname sysvar)
)
)
(if *Function* (VL-CATCH-ALL-APPLY *Function*)) ;_执行函数
(if (= *UndoMode* 1)
(if (= 8 (logand (getvar “undoctl”) 8))
(command “_undo” “_e”)
)
)
)
)
(setq *error* *olderror*
*olderror* nil
*Function* nil
*UndoMode* nil
)
(or (wcmatch (strcase msg) “*BREAK,*CANCEL*,*EXIT*”)
(princ (strcat “\n** Error: ” msg ” **”))
)
)
(if (or (= *UndoMode* 1) (= *UndoMode* 2))
(progn
;;如果有活动编组,先结束编组
(if (= 8 (logand (getvar “undoctl”) 8))
(command “_undo” “_e”)
)
(command “_undo” “_BE”) ;_ 编组开始
)
)
(if syslst
(while (and (setq sysname (car syslst))
(setq sysvar (cadr syslst))
)
(setq *sysvarInit*
(append *sysvarInit*
(list sysname (getvar sysname))
)
)
(setq syslst (cddr syslst))
(setvar sysname sysvar)
)
)
(princ)
)
;;;自定义通用错误处理恢复函数
;;(gxl-error-end) 恢复*error*
(defun gxl-error-end ()
(if (= 8 (logand (getvar "undoctl") 8))
(command "_undo" "_e")
)
(if *olderror*
(setq *error* *olderror*
*olderror* nil
) ;_ 恢复*error*函数
)
(if *sysvarInit* ;_ 恢复储存的系统变量
(while (and (setq sysname (car *sysvarInit*))
(setq sysvar (cadr *sysvarInit*))
)
(setq *sysvarInit* (cddr *sysvarInit*))
(setvar sysname sysvar)
)
)
(setq *Function* nil
*UndoMode* nil
)
(princ)
)
(defun c:tt4()
(gxl-error-init1 (list ‘blipmode 0 ‘cmdecho 0 ‘osmode 0) ‘tt1 2) ;_ 出错只编组
(defun tt1 () ;_ 出错后*error*要执行的动作
(alert “出错啦!”)
)
;;;主程序内容
(setq p1 (getpoint "\n输入第一点: ")
P2 (getpoint p1 "\n输入第二点: ")
P3 (getpoint p2 "\n输入第三点: ")
)
(vl-cmdf "_.pline" p1 p2 p3"c")
(gxl-error-end)
(princ)
)
|
|