*push-error-using-stack* (AutoLISP) 
错误处理函数,指示在自定义处理程序中使用 AutoLISP 堆栈中的变量*error* 支持的平台:Windows 和 Mac OS 签名(*push-error-using-stack*) 没有参数。 返回值类型:T 返回值 。T 言论允许从自定义处理程序访问在发生错误的函数中定义的堆栈上的本地 AutoLISP 变量。对函数的调用将覆盖之前对 .*error**push-error-using-stack**push-error-using-command* 如果调用或未调用,则默认情况下 AutoLISP 的工作方式与被调用的相同。*push-error-using-command**push-error-using-stack**push-error-using-stack* 注意:在本地自定义处理程序中使用该函数时,不能使用此函数。command*error* 
 
例子下面的示例演示了该函数的用法。*push-error-using-stack* (setq var1 "Global1"      ; Set some global variables
      var2 "Global2")
(defun mySub_err (err_msg)
    (if (/= err_msg "Function cancelled")
      (progn
        (prompt (strcat "\nError: " err_msg))
        (prompt (strcat "\nLocalSub1: " var1))
        (prompt (strcat "\nLocalSub2: " var2))
        (terpri)
      )
    )
    (command-s "._undo" "_e")
    (command-s "._U")  
    (setq *error* olderr)
  (princ)
)
(defun subUtil (val / olderr var1 var2)
    (*push-error-using-stack*)         ; Indicates if the custom error handler has access to local
                                       ; variables defined in his function
    (setq olderr *error*
          *error* mySub_err)
    (command "._undo" "_group")        ; The following will not be executed in this sample, but is good 
                                       ; framework for setting up your own error handlers
    (setq var1 "Sub1"                  ; Set some local variables
          var2 "Sub2")
  
    ;; Perform your tasks here
    (strcat "Foo" val)
  
    (command "._undo" "_e")
    (setq *error* olderr)              ; Restore old *error* handler
    (*pop-error-mode*)                 ; End the use of *push-error-using-command*  
)
(defun my_err (err_msg)
    (if (/= err_msg "Function cancelled")
      (progn
        (prompt (strcat "\nError: " err_msg))
        (prompt (strcat "\nLocal1: " var1))
        (prompt (strcat "\nLocal2: " var2))
        (terpri)
      )
    )
    (command "._undo" "_e")
    (command "._U")
    (setq *error* olderr)
  (princ)
)
(defun myUtil (val / var1 var2)
    (setq olderr *error*
          *error* my_err)
    (*push-error-using-command*)       ; Indicate use of Command function instead of Command-s
                                       ; in the custom error handler
  
    (setq var1 "Local1"                ; Set some local variables
          var2 "Local2")
    (command "._undo" "_group")        ; The following will not be executed in this sample, but is good 
                                       ; framework for setting up your own error handlers
  
    (subUtil val)                      ; Call to a custom function that uses *push-error-using-stack*
  
    (/ 1 0)                            ; Call a function with incorrect values to trigger the custom error handler
                                       ; Remove when setting up your code
   
    ;; Perform your tasks here
  
    (command "._undo" "_e")
    (setq *error* olderr)              ; Restore old *error* handler
    (*pop-error-mode*)                 ; End the use of *push-error-using-command*  
)
 
  加载示例代码后,在命令提示符下输入 (myutil 1) 以输入嵌套函数的错误处理程序,并输入 (myutil “String”) 以测试 main 函数的错误处理程序。 相关概念 | 
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1   苏公网安备32011402011833)
GMT+8, 2025-11-4 15:10
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.