Hello,
I have come to the very last point of the app development (no, its not doing the docs)
which is a decent error handling.
If the app crashes (for whatsoever reason) corona/lua will throw an error, leave the function and go on with execution. This can be a problem since this function might need to do something important which then causes other errors or ugly graphic glitches such as flickering transitions or a shattered stage.
Using pcall or xpcall does not really help when using corona since inner functions and nested (async) calls will not get handled properly. Furthermore if using classes and oo the code will become quite insane. I am using middleclass for oo which has been a great help but does not work well together with pcall. So again, placing pcall everywhere might work (despite the overhead) most of the time but is not a very good solution and has problems with functions that have return values and nested functions.
Since a “real” exception handling is not something we can do with lua[1][2] to handle errors appropriate, the only thing I want to do is:
- Catch the Runtime error (catch-all)
- Save an error.log with device, os, app state, stacktrace and the error.
- If there is network send the error.log (if the user is ok with it) to my server so i can examine it (or send it next time)
- Open an alert() window telling the user that it all went to hell.
- Perform os.exit() to close the app to prevent any unexpected behavior.
Why do I want to do this? First of all it is very hard to find a bug by 1 star “frequent crashes” ratings and second I don’t want to get unexpected behavior which will look very unprofessional to the user. Also a crash with no message might leave a bitter taste. Of couse if something fails hard and result in a segfault there might be no holding back but no solution is perfect.
So the question is: Is there a way to catch errors in Corona? Ideal would be to register a runtime event listener that listens for errors. I guess this would improve the quality of the apps made with corona significantly.
Any ideas on this?
Alex
[1] http://www.lua.org/wshop06/Belmonte.pdf
[2] http://failboat.me/2010/lua-exception-handling
[import]uid: 11772 topic_id: 16330 reply_id: 316330[/import]
[import]uid: 3826 topic_id: 16330 reply_id: 60833[/import]
besides that exception handling is always a good idea even SymbianOs has trapd()