Error object cannot be nil

Lua will change a nil as error object to a string message, so that it
never reports an error with nil as the error object.
This commit is contained in:
Roberto Ierusalimschy
2025-02-28 14:53:58 -03:00
parent 127a8e80fe
commit ee99452158
4 changed files with 23 additions and 8 deletions

View File

@@ -290,7 +290,9 @@ an @def{error object}
is propagated with information about the error.
Lua itself only generates errors whose error object is a string,
but programs can generate errors with
any value as the error object.
any value as the error object,
except @nil.
(Lua will change a @nil as error object to a string message.)
It is up to the Lua program or its host to handle such error objects.
For historical reasons,
an error object is often called an @def{error message},
@@ -8082,6 +8084,8 @@ multiple assignment:
The default for @id{a2} is @id{a1}.
The destination range can overlap with the source range.
The number of elements to be moved must fit in a Lua integer.
If @id{f} is larger than @id{e},
nothing is moved.
Returns the destination table @id{a2}.
@@ -9402,6 +9406,11 @@ declare a local variable with the same name in the loop body.
A chain of @id{__call} metamethods can have at most 15 objects.
}
@item{
In an error, a @nil as the error object is replaced by a
string message.
}
}
}