lua-users home
lua-l archive

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


Hi,

 

I am trying to generate a traceback when garbage collection raises an exception.  This of course can happen if the ‘__gc’ metamethod raises an exception.  The problem I am encountering is that the message handler is ignored:

 

C:\Tools\lua-5.3.5_Win64_bin>lua53

Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio

> t = setmetatable({}, {__gc = function(t) junk() end}) t=nil

> print(xpcall(collectgarbage, debug.traceback))

false   error in __gc metamethod (stdin:1: attempt to call a nil value (global 'junk'))

 

I would of expected a traceback, but it turns out that the message handler is not called when the exception occurs.

In our system, we have many different threads so it makes it difficult to pin down the object that is causing the garbage collection exception.  Am I doing something wrong or is this a limitation?

 

Guenther