When should I use the "error()" command?

There is a very rare situation in my game under construction which I have not yet been able to identify the origin, since repeating the same steps a second time the error does not occur.
But I was able to identify a line, where if a value is missing, it will generate errors later on.
To avoid this, I inserted the error instruction with the warning about this missing value:

function Ang(Angle)
	if Angle == -180 then 
        Angle = 180
	else 
		error("Invalid Angle: ", Angle)
	end
end

The problem is that error aborts the script, thus interrupting the entire game.

My question is, should I use the error command? Because once my game is lauched, it will stop the game, creating the worst scenario for the players…

1 Like

Here’s some information:

1 Like

You use it for exactly that; aborting the program. You could warn instead, which emits a warning in yellow text and doesn’t abort execution.

2 Likes

There are a couple of use-cases, but a good example is if you are writing code for someone else to use.
Pardon the dumb example.

function divide(x, y)
    if y==0 then error("Second argument to 'divide' must not be zero!") end
    return x/y
end