[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Have you noticed how nil is a separate type?
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 21 Feb 2017 19:52:42 +0200
2017-02-22 5:16 GMT+02:00 Martin <eden_martin_fuhrspam@gmx.de>:
> On 02/20/2017 03:36 PM, Soni L. wrote:
>>
>> local function f(x)
>> --assert(type(x) == "function")
>> return {dothing=x}
>> end
>>
>> local v = f(nil)
>>
>> v:dothing()
>>
>> If you
>> uncomment the assertion, you get an error on line "local v = f(nil)"
>> instead, which is much more helpful.
>
> I think official way to handle this is change assert() to error() which
> can specify in second parameter level of code that should take
> resposibility.
>
> if (type(x) ~= "function") then
> error('wrong arg type passed', 2)
> end
>
> I've implemented similar functionality as family of assert_nil(),
> assert_boolean(), ... global functions.
I think I'm digressing here but ...
I use `assert` when the error is one of programming (i.e. it should
never happen, but unfortunately does) and `error` is one of the
user of the packages (i.e. bad input).