Re: general purpose C++ exception handler in lisp
Andrew Wolven <[email protected]> Thu, 13 Feb 2025 17:20:21 -0600
| Newsgroups | gmane.lisp.steel-bank.general |
|---|---|
| Message-ID | <CANhGVvQ=g46fahtuZoAXRoha71XxyO67AZSMqpE9y47-gQCLqQ@mail.gmail.com> |
Grégory, Yes, indeed I would like something like "handler-case" but for C++ exceptions instead of common lisp conditions. I understand that some SBCLs handle C++ exceptions like win32, because the OS requires that the executable handle them. I'm not sure about unix implementations of SBCL, but I specifically need to be able to gracefully handle the exception at the location I choose, and not somewhere at the beginning of the stack. So I was hoping someone who might have some experience setting up C++ exception handlers at various places in a stack, and on various OSes could chime in and give a rundown of how doable this may be, but I don't think anyone is listening. -AKW On Wed, Feb 12, 2025 at 3:07 AM Grégory Vanuxem <[email protected]> wrote: > Hi Andrew, > > I respond to you question because I use libjulia.* (julialang.org) with > "does-not-catch-exceptions/errors-let-my-underlying-lisp-catch-an-handle-them". > And to add more uncertainty and to start with, I am not a real CL coder I > do what I can. Do you mean something like: > > (defun divide (numerator denominator) > (handler-case > (/ numerator denominator) > (division-by-zero () > (format t "Error: Division by zero is not allowed.")))) > > (Copilot generated, do not burn me please ;)) No tested code frankly but I > guess the important keyword for you is 'handler-case'. The SBCL source code > has easily finding files(s) that handle floating point exceptions to handle > them. This is another subject, more linked to the material, but that can > give you some hints). > > - Greg > > Le sam. 8 févr. 2025 à 21:49, Andrew Wolven <[email protected]> a écrit : > >> 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 >> > _______________________________________________ Sbcl-help mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sbcl-help