lua-users home
lua-l archive

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


> But I am working in an environment - embedding Lua into an existing
> large and complex program, namely the PostgreSQL backend - which has its
> own rules about error handling that simply do not allow this. In
> particular, I can't guarantee that closing a database cursor won't throw
> an error, and if it does, then I can't allow execution of arbitrary Lua
> code until after the subtransaction has been cleaned up (which requires
> propagating the error).

I fully agree that finalizers should not throw errors. If closing a
database cursor must throw an error and you can't allow execution of
arbitrary Lua code etc., then probably you shouldn't close cursors
during finalizers. Instead, for instance, the finalizer would
only prepare some data indicating that the cursor must be closed.
Periodically (e.g., when creating new cursors?), your program should
consult this data and close cursors if needed.

As Gé pointed out, propagating a finalizer error is pointless. You
are interrupting code that has nothing to do with the error, and
cannot know how to handle it.

-- Roberto