general purpose C++ exception handler in lisp

Andrew Wolven <[email protected]> Sat, 8 Feb 2025 14:46:41 -0600
Newsgroups gmane.lisp.steel-bank.general
Message-ID <CANhGVvTg0_oJbRSOJKypzqnokBsCXL4feOn6HrzALuhoMTC+Zw@mail.gmail.com>
I'm working with some rather large C++ libraries.

In the past, I have written C wrappers for C++ calls, which inside the
wrapper, uses a C++ try/catch form which catches any exception (...) and
calls a lisp callback function which signals a lisp error.

It would behoove my build process and [possibly] reduce complexity if I
could get rid of the C wrappers and call the C++ methods directly from Lisp
with the ffi.

The problem is, these C++ methods sometimes throw exceptions.  It would be
really cool if I had a macro, like 'with-try/catch' where I could set up a
C++ exception handler frame, and execute the body of the macro, which is
lisp code, but most likely contains a foreign function call to a C++ method
which can throw.

The catch portion could translate the C++ exception into a lisp condition
and signal the lisp condition.  I don't think I would rethrow if a
translation is not found, but rather signal a general C++-error lisp
condition.

I've seen some posts which indicate that something like this may be doable
on Windows (windows amd64 is my primary platform), but it would also be
good if it worked on Linux and Macos.

Does anyone have thoughts on how I could implement such a macro?

Thanks,
Andrew Wolven

_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help