A suggestion on error handling (Mojo)

Monkey Forums/Monkey Programming/A suggestion on error handling (Mojo)

Amnesia(Posted 2012) [#1]
I'm aware that (at least on Android and HTML5) Monkey currently throws a nice little dialog box at any error that happens. I'm not sure if the same happens on iOS (but if it doesn't, it's still possible to "catch" exceptions on iDevices with NSSetUncaughtExceptionHandler) or the other targets.

Whatever the case is (whether monkey shows a message or not) I think it would be nice if we -as developers- could be able to execute some of our own code once something happens and the app crashes.

By instance, if we keep some record of game context information globally (like the state of the game, assets loaded so far, etc) we could display that on the debug console when our game unexpectedly dies which will be helpful to catch hard-to-replicate bugs that happens once in a lifetime.

Or perhaps we would like to keep some sort of error log, or give the user the chance to send an automated report of the crash.

My suggestion is as simple as adding an "OnDie (error: String)" method to App (in mojo) that will be called when the game crashes and we can override (through inheritance) if needed. I already did a little test hacking mojo and it works like a charm. It would be nice if mojo offered this out of the box.
Of course, it adds a bit of a danger, since the code in the "handler" could also generate an error, but that's a risk common to most (all?) error handlers.

So, what do you guys think?


Shinkiro1(Posted 2012) [#2]
What about Exceptions? http://blitz-wiki.appspot.com/Language_reference#exceptions
PS: Sorry, didn't read carefully.


Amnesia(Posted 2012) [#3]
Exceptions catch stuff you throw purposefully. As far as I know they don't catch platform errors. Those are handled by Monkey.


muddy_shoes(Posted 2012) [#4]
Discussed previously. Apparently you would only ever want to catch a fatal error, perhaps display a custom message, log some info or possibly even attempt a recovery if you're writing nuclear reactor controllers: http://www.monkeycoder.co.nz/Community/posts.php?topic=3098#31778


Amnesia(Posted 2012) [#5]
So we basically need to discontinue our use of Monkey for our line of nuclear reactor controllers? that's bad news :/

Anyway, I'm afraid there are a few problems not only specific to the context of nuclear devices (like memory leaks or textures suddenly disappearing from VRAM) which are hard to replicate unless you happen to have infinite time and money (as to buy every device on the market). We thought the perfect solution relied on user reports. Perhaps I'll ask the user every time he opens the game "Did the game crash? If so, please tell us how."

. . .

Ok, seriously talking; I'm fine with Monkey handling those, but I also want the chance to call my own code to do additional stuff in case of fatal errors.


ziggy(Posted 2012) [#6]
this, and haveing the chance to inspect the call stack on runtime (even if it's only on a debug build) is very useful to me on other languages, so I would love to have the oportunity to do this on Monkey too, This time, I agree with muddy_shoes.


muddy_shoes(Posted 2012) [#7]
I've altered my install so that the StackTrace command is available to my Monkey code. I don't know if Diddy or the Monkey extension stuff does the same.


mr_twister(Posted 2012) [#8]
I second the idea.

Although I understand the way Mark thinks about the whole thing, let's look at the bright side: in the other thread Mark said something about adding a sort of OnError() (maybe) so he is at least willing to go that route (if enough people feel like the feature should be there, I guess).

So count me in if votes are needed.