Standard Library: Panic
Terminate the program upon an unexpected program state
In constrast with errors (which signal anticipated error states), panics are used to indicate an unexpected program state from which recovery is not possible. Raising a panic terminates the program.
Panic.raise(message)
Raise a panic with the given message string.
score = -10
if score < 0 then
Panic.raise("score should never be negative")
end
Error: score should never be negative
Panic.unimplemented()
Raise a panic indicating an unfinished implementation.
score = 101
if score > 100 then
Panic.unimplemented()
end
Error: not implemented
Panic.unreachable()
Raise a panic indicating an unexpected program state.
score = -10
if score >= 0 then
score /= 2
else
Panic.unreachable()
end
Error: encountered unreachable code