发生错误时如何使Clozure退出

时间:2018-10-19 05:12:22

标签: common-lisp clozure-cl

我正在尝试在CCL下运行程序,因此,由于某种原因该程序完成运行后,应退出操作系统。当前正在使用此命令行(在Windows上):

\ccl\wx86cl -l test.lisp -e (quit)

当程序成功运行至正常完成时退出,但是如果出现错误(例如内存不足,它将最终进入调试器。发生错误时,如何告诉Clozure也退出?

1 个答案:

答案 0 :(得分:5)

不仅要捕获所有错误,而且还希望防止在调用INVOKE-DEBUGGER时进入调试器。您可以将*DEBUGGER-HOOK*设置为在未处理的错误时退出的函数。

$ ./bin/ccl/lx86cl64 
Clozure Common Lisp Version 1.11.5/v1.11.5  (LinuxX8664)

For more information about CCL, please see http://ccl.clozure.com.

CCL is free software.  It is distributed under the terms of the Apache
Licence, Version 2.0.
? *debugger-hook*
NIL
? (setf *debugger-hook* 
        (lambda (error hook)
          (declare (ignore hook))
          (format *error-output* "Crash: ~a" error) 
          (quit)))
#<Anonymous Function #x302000998C3F>

现在,使用未处理的错误对其进行测试:

? (error "Oh no")
Crash: Oh no

然后,您回到外壳了。

请注意,BREAK总是进入调试器,因为它会将*debugger-hook*绑定到NIL(这是为了进行调试)。

相关问题