Embedded ECL lisp error handling

爱⌒轻易说出口 提交于 2019-12-13 01:46:18

问题


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 have no documentation on its embedded API and no documentation on error handling...

Can you suggest how to implement that?


回答1:


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) 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) ...) ...))

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

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.

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



来源:https://stackoverflow.com/questions/7755661/embedded-ecl-lisp-error-handling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!