|
To be precise, the documentation indicates that 'message' is not optional.
Thus the result of error() is undefined.
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.
if somethingWrong then
myLogger:log(Level.Error, extraData, "this isn't looking good!")
error() -- hope to also get stack trace without extra calls
But I'm probably making up a problem for myself...end
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 messageTo be precise, the documentation indicates that 'message' is not optional.
> argument:
>
> error (message [, level])
Thus the result of error() is undefined.
I suspect that it is intended. It gives you something not achievable by
> I'm wondering if this is intended behavior or no?
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
The situation is different. 'error' is unconditional, 'assert' is conditional.
> 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 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.