lua-users home
lua-l archive

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


2009/9/12 GrayFace <sergroj@mail.ru>:
> Hi all,
>
> I have stumbled upon the fact that there's no way to assign an error handler
> to a coroutine. I want all errors reported with call stack and variables
> trace. This seems impossible in coroutines and inconvenient in pcall either,
> due to xpcall not taking any argments to the function. So, my suggestion is
> a default error handler that would be called if there's no error handler
> supplied.
>
> I can send a patch with my implementation if you're interested.

You don't need an error handler because the stack is not unwound when
a coroutine dies due to an error. This code will append the standard
traceback you're used to.

do
  local function aux_resume (co, status, ...)
    if status == false then
      return false, debug.traceback(co, (...));
    else
      return status, ...;
    end
  end
  local resume = coroutine.resume;
  function coroutine.resume (...)
    return aux_resume(co, resume(...));
  end
end

-- 
-Patrick Donnelly

"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."

- Benjamin Franklin