Error Handling in Monkey

Monkey Forums/Monkey Programming/Error Handling in Monkey

Rixarn(Posted 2011) [#1]
I haven't seen any Try/Catch or equivalent thing, so i guess this has to be done kind of manually so.. How would yo do error handling in Monkey?


Dabz(Posted 2011) [#2]
local image:Image = LoadImage(blah,blah)

If image = Null then GoBerserk()


Amonst other object relate guff

Dabz


Samah(Posted 2011) [#3]
Diddy has a simple assertion module you could use.
http://code.google.com/p/diddy/

Local image:Image = LoadImage(blah,blah)
AssertNotNull(image, "Couldn't load the image!")

This says "image isn't allowed to be null. If it is, please throw this error message."

Basically you give it the condition you expect to pass, and if it fails it will call Error for you. There are lots of other assertion methods for checking equality, booleans, and number ranges.

Be aware that if you do any string concatenation or method calls for the message, they will be always be executed even if the assertion passes.


Rixarn(Posted 2011) [#4]
Cool! Seems like Diddy is an usefull lib... will play with it, thanks :)