lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


you can still capture uncaught C++ exception in C, there are existing mechanism, like SOH and even if your C compiler does not have it, you can get it from OS-level services/API.
Your C code may be part of a C-library having other mechanisms (e.g. in a framework like JNI, or some plugin mechanisms for web browsers, or media players, or SQL clients, or other language integration libraries (PHP, Python, .Net/Mono, PostScript engines, BPF for kernel integration, and so on) which almost always include such C library for their integration You could even have integration of Lua within another Lua acting as an isolation layer...
And if it's not enough, there are also architecture solutions (e.g. interrupt handlers, BIOS interfaces) that you can use in native (or virtualized) assembly.
you need a small generic handler in your C++ library that will forward the exception possibly as an error without necessary crashing the app with some forced exit() and loosing all current state. it's up to you to kwow how you'll recover, or what you'll still want to try saving to recover differently (such as by restarting the process or rebooting the device/OS, and let it perform cleanup at startup according to the state that could correctly be saved).

Le ven. 18 sept. 2020 à 20:34, Viacheslav Usov <via.usov@gmail.com> a écrit :
On Fri, Sep 18, 2020 at 7:40 PM Albert Krewinkel
<albert+lua@zeitkraut.de> wrote:

> I believe languages like Rust and Go face similar issues.

Every language, including C, faces issues when Lua errors propagate
through code that does not expect that.

Paradoxically, C++ fares better, because Lua can be compiled in the
C++ mode, which will then use the standard C++ facility - exceptions -
for Lua errors, which works well with properly written C++ code. The
drawback is that exceptions may misbehave when they need to propagate
through a layer of non-C++ code, say a library written in C. This is
usually not a problem when libraries are statically linked. Note that
Francisco said he uses C++ and he uses static libraries, which is
probably why he did not mention this.

Cheers,
V.