Jump to content




return error('This is an error message') or error('This too', 2)?


  • You cannot reply to this topic
4 replies to this topic

#1 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 14 July 2016 - 05:59 PM

My question is:
What is better?
To return the error or to send it a plain above?

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

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 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

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 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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