lua-users home
lua-l archive

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


assert () is the best in your case (more verbose)

error () may also be helpful
especially if your error message requires complex evaluation:
-- This requires 'some_complex_call ()' even if there was no error:
assert (bar ~= "", "Error: "..some_complex_call ())

-- While this will call 'some_complex_call ()' only in case of error
if bar == "" then
   error ("Error: "..some_complex_call ())
end

On Sat, Jun 25, 2011 at 5:22 PM, marbux <marbux@gmail.com> wrote:
> Hi, all,
>
> I've spent a couple of hours now looking for the answer without
> success. Is there a simple method to terminate a script upon an error
> condition that occurs within a function, E.g.,
>
> function foo(bar)
>   if bar == ""
>      ???
>   end
>   ...
> end
>
> Appreciate any guidance here.
>
> Best regards,
>
> Paul
>
>