lua-users home
lua-l archive

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



On Fri, Sep 19, 2014 at 4:05 PM, Jorge <xxopxe@gmail.com> wrote:
local ret, err = lib.call('resource_name')
if ret then
        --dostuff with ret
else --as long as I care
        if err == "does not exist" then
                --think hard what to do and why i'm here
        else
                error(err)
        end
end

First, I appreciate anyone and everyone that is sticking with me on this. I hope that I do not sound argumentative. The responses thus far are helpful.

Your example is essentially how I do everything now. Here is the pcall variant, for comparison:

```
local success, ret = pcall(lib.call, 'resource_name')

if  success then
  --dostuff with ret
else --i care, otherwise i wouldn't have `pcall`ed
    if ret == EAGAIN then
       --as a a silly implementation of what life looks like 
       --when error is used for non-errors.
       sleep(1)
       return this_function(...) 
    else
        --could be resource not found, could be shutdown, could be a bug, who cares! I can't do anything about it here.
        error(ret)
    end
end
```

So, this is partly a style question and partly a substance question. I believe that my attraction to this new way of thinking is:

1: One way to do something is much better than two ways.
2: Lua's `error` function is not slow, especially if I write my own, which wouldn't print the stack. I could return literally "EAGAIN", with no line numbers or stack trace, if that's my error.

AND, I think i'm mostly talking about internals, anyway. The motivation of my question stemmed from having trouble dealing with errors in a sane way. How I deliver them to customers is somewhat (but I guess not really) of a different question, which should be more heavily influenced by conventions.

-Andrew