assert
Takes in a boolean value where, on the condition that it evaluates to false or nil an error is thrown with the specified message.
|
|||
Throws an error with specified error message due to the condition being false. | |||
Code | assert(false, "example error message")
|
||
Output | program.lua:1: example error message
|
|
|||
Throws an error when something other than an even number is given | |||
Code | function assertNumber(number)
assert(number/2 == math.ceil(number/2), "this is odd")
end
assertNumber(4) --Passes by this since it is an even number
assertNumber('foo')
|
||
Output | program.lua:5: this is odd
|
assert Function | |
---|---|
Syntax assert(
| |
Returns | nil |
API | Base globals |
Source | CC:Tweaked |
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.