lua-users home
lua-l archive

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


2013/8/2 Dmitry Pashkevich <dpashk@gmail.com>:

> However, calling error() without arguments seems to make Lua die silently
> without printing stack trace.

> The documentation doesn't say anything about omitting the first message
> argument:
>
> error (message [, level])

To be precise, the documentation indicates that 'message' is not optional.
Thus the result of error() is undefined.

> I'm wondering if this is intended behavior or no?

I suspect that it is intended. It gives you something not achievable by
any non-nil message. Nothing printed, but the OS can detect the error.

    $ if `lua -e ''`; then echo 'no error'; else echo 'error'; fi
    no error
    $ if `lua -e 'error()'`; then echo 'no error'; else echo 'error'; fi
    error

> IMO it would make sense to
> still print stack trace (and maybe output some default text e.g. error) even
> if no message is provided, because that's how theassert() function works.

The situation is different. 'error' is unconditional, 'assert' is conditional.
The user of 'assert' wants to know where in the program it happened.
The user of 'error' with no message just wants abort the program.

You can always do `error""` or `error"default text"` yourself.