463 posts
Location
Star Wars
Posted 14 July 2016 - 06:59 PM
My question is:
What is better?
To return the error or to send it a plain above?
3057 posts
Location
United States of America
Posted 14 July 2016 - 07: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
2427 posts
Location
UK
Posted 14 July 2016 - 08: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
463 posts
Location
Star Wars
Posted 14 July 2016 - 09:53 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
You can reach it, with return error(msg, 2).
Does handle pcall return error(msg) and error(msg, 2) the same?
7083 posts
Location
Tasmania (AU)
Posted 15 July 2016 - 12:40 AM
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.