lua-users home
lua-l archive

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



On Fri, May 31, 2019 at 8:37 AM Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:
I understand that handling errors in GC is tricky, but having a place
where errors are caught and then ignored is a complete showstopper in an
environment where errors MUST be propagated up to a point where they can
be safely handled (and no, this can't be done inside the __gc method
itself).


The problem is that there's no 'up' to propagate to. If the GC would throw an error it lands in a random block of code, which means that your code would have to be able to handle any error in any location, and using third-party libraries would be very risky.

This problem is not limited to Lua, in C# the 'Dispose' method of an object may be called from a thread unrelated to your program, which is owned by the GC, and handling an error there is even trickier.

Code called from __gc should only release resources and such, and handle its own errors. The new generational GC may delay the call to __gc for a *long* time, so if you can use the new __close metamethod you probably should use that instead.