嵌入式ECL lisp错误处理 [英] Embedded ECL lisp error handling

查看:178
本文介绍了嵌入式ECL lisp错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务:在我的项目中嵌入ECL lisp,设置错误处理和详细的错误报告(发生错误等等)

Task: Embed ECL lisp in my project, setup error handling and detailed error reporting (where occurred, kind of error, etc.)

我试图这样做这样的方式:

I tried to do that such way:

cl_def_c_function_va(
    c_string_to_object("SYSTEM:UNIVERSAL-ERROR-HANDLER"),
    LispErrorHandler);

ECL没有关于其嵌入式API的文档,也没有关于错误处理的文档...

ECL have no documentation on its embedded API and no documentation on error handling...

你可以建议如何实现吗?

Can you suggest how to implement that?

推荐答案

没有全局错误处理程序因为这不是Common Lisp的理念。如果要处理错误,请执行lisp方式。

There is no global error handler because this is not the Common Lisp philosophy. If you want to handle errors, do it the lisp way.

1)创建一个使用HANDLER-CASE或HANDLER-BIND设置相应错误处理程序的函数,捕获要评估的表单周围的错误。这样的一些东西就像

1) Create a function that uses HANDLER-CASE or HANDLER-BIND to set up the appropriate error handlers and catch errors around a form that is to be evaluated. Something like

(DEFUN MY-EVAL(FORM)
(HANDLER-CASE(EVAL FORM))
(ERROR(C)...)
(MY-ERROR(C)...)
...))

(DEFUN MY-EVAL (FORM) (HANDLER-CASE (EVAL FORM) (ERROR (C) ...) (MY-ERROR (C) ...) ...))

此函数可以在C代码中定义并调用。

This function may be defined in your C code and invoked.

2)使用ECL创建的捕获所有错误的功能。最重要的是si_safe_eval(form,environment,error_value)。它在ENVIRONMENT(通常为Cnil)中评估lisp FORM,并返回其输出或ERROR_VALUE(如果有某些错误)。

2) Use the functions that ECL creates that catch all errors. The most important one is si_safe_eval(form, environment, error_value). It evaluates the lisp FORM in an ENVIRONMENT (Typically Cnil) and returns its output or ERROR_VALUE if it got some error.

使用一种或其他技术的一些示例:
http://thread.gmane.org/gmane.lisp.ecl.general/5365(第二条消息)
http://thread.gmane.org/ gmane.lisp.ecl.general / 8526 / focus = 8529

Some examples that use one or the other technique: http://thread.gmane.org/gmane.lisp.ecl.general/5365 (2nd message) http://thread.gmane.org/gmane.lisp.ecl.general/8526/focus=8529

这篇关于嵌入式ECL lisp错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆