My question is:
What is better?
To return the error or to send it a plain above?
return error('This is an error message') or error('This too', 2)?
Started by Sewbacca, Jul 14 2016 05:59 PM
4 replies to this topic
#1
Posted 14 July 2016 - 05:59 PM
#2
Posted 14 July 2016 - 06:25 PM
They do the same thing, but the former has some restrictions on where you can use it. Also, in some cases you may want to blame the caller above the caller (3). This isn't enforced by the former
#3
Posted 14 July 2016 - 07:07 PM
error(message,2) I would use for functions/APIs reciving bad arguments. In my mind error(message) is for when your own code has an error
#4
Posted 14 July 2016 - 08:53 PM
KingofGamesYami, on 14 July 2016 - 06:25 PM, said:
They do the same thing, but the former has some restrictions on where you can use it. Also, in some cases you may want to blame the caller above the caller (3). This isn't enforced by the former
You can reach it, with return error(msg, 2).
Does handle pcall return error(msg) and error(msg, 2) the same?
#5
Posted 14 July 2016 - 11:40 PM
Lupus590, on 14 July 2016 - 07:07 PM, said:
error(message,2) I would use for functions/APIs reciving bad arguments. In my mind error(message) is for when your own code has an error
Note it's "error(message,2)" vs "return error(message)". The latter performs a tail call, knocking the current function off the stack... meaning that the error will point to the calling function.
Thing is that you can stack multiple tail calls, so who knows where the error will actually end up pointing. I would consider manual specification of the error level to be more readable.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











