Lua "try" catch?

Is there an easy way to implement a try/error catch? It’s needed to avoid problems with multiple collisions (instead of receiving errors I could just call a function to handle the error)

In languages like python it would be

try:
my function here
except:
print(“error!”)

and since lua is close to python I figured it’d have something like this.

Help would be appreciated, thanks! [import]uid: 9033 topic_id: 4426 reply_id: 304426[/import]

whoops, nevermind! I already found the solution. For anyone else wondering, just put this: if unexpected_condition then print(“error!”) end before any blocks that may contain an error (or just inside a function)

you can obviously change the print to whatever you want. [import]uid: 9033 topic_id: 4426 reply_id: 13795[/import]

Additionally, if you’re only looking to check for errors, you may be interested in the “assert()” function native to Lua.

http://developer.anscamobile.com/reference/index/assert ( docs say it’s new, but it’s really just part of the Lua language ) [import]uid: 12405 topic_id: 4426 reply_id: 13886[/import]

Hi, coming in late to the conversation, but the Lua equivalent of a try/catch would be the pcall() function:

http://www.lua.org/pil/8.4.html

Thanks,
Darren [import]uid: 1294 topic_id: 4426 reply_id: 17818[/import]