lua-users home
lua-l archive

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

Mike Pall wrote:
> Robert Raschke wrote:
>> function foo()
>> 	assert(nil, "an error")
>> end
>> dofile("conf")
>> And the file conf just says "foo{}", then I'd like to get an error
>> .../conf:1: an error
>> instead of
>> .../main.lua:3: an error
> See the section in the manual about the error() function.
>> Is there an easy way to do this?
> function assert3(ok, ...)
>   if not ok then
>     error(..., 3)
>   end
>   return ok, ...
> end

OK, this will help me do my own error reporting in the way I want.  I
guess if any of the libs I use tumbles with an assert, it should
report that location and not the conf one.  On the other hand, I'm
making use of LuaSocket's SMTP support, and it would be great to give
back any SMTP errors still pointing at my wrapper.

I'm assuming that writing my own error() function to parse the result
of debug.traceback() would be quite yucky.  Not that I really want to
go down that route.

Alternatively, I could attempt to assert() my parameters to death,
ensuring I never get an error further down the line.  That doesn't
sound very realistic either.  Hmm, some more thinking required.

Oh, I forgot all about pcall(); I think that might solve my problem.
I can catch the errors further down and report them however I want