Runtime Error Pop-upAs those of you who build for Android have already noticed we’ve made changes to the way we report errors. It was necessary to do this on Android first because improved run-time error handling was a prerequisite to getting the custom Android permissions feature implemented.

Now it’s time for the rest of the platforms (iOS and simulators) to catch up and implement run-time error handling too.  We’re also rolling out the unhandled error listener, which can be used to trap errors which would otherwise trigger the Runtime Error pop-up.  It can’t fix your run-time errors but it can hide them.

This is an example of how the run-time error handler is defined:

local function myUnhandledErrorListener( event )

    local iHandledTheError = true

    if iHandledTheError then
        print( "Handling the unhandled error", event.errorMessage )
    else
        print( "Not handling the unhandled error", event.errorMessage )
    end
    
    return iHandledTheError
end

Runtime:addEventListener("unhandledError", myUnhandledErrorListener)

The event table passed to the listener has errorMessage and stackTrace parameters which are respectively, the error message that resulted from the error and the stack trace at the point of the error. Returning true from the listener will suppress the pop-up alert message and allow the app to continue running. Returning false will show the pop-up and abort the app (the default action if the unhandledError listener is not implemented in your code) but you’ll have the opportunity to do things like log application state to the console.

The major change you’ll see in the next daily build is a pop-up message when a run-time error occurs. Adding the above mentioned unhandledError listener is needed if you want to trap and suppress the pop-up message and app aborting.

The above feature should be available starting with daily build 1044 and above.

  1. This is fantastic! This already did help me with some android versions of my apps and to have this now for iOS & the simulator is most helpful.

    Thanks!

  2. Any tips or best practices on what to do with an error captured by the listener when running on a released app? Obviously on a development build I want to see the error message and as much info as I can get to track down the problem, but a 9-year-old running a release version of my game isn’t going to know what to do with, or care, about some esoteric error message. Most likely I want to suppress the message and prevent the crash. What’s a good way for me to get info about the error while still providing a reasonable customer experience?

  3. Wouldn’t it be more logical to have the default state be that is on. That it blocks the pop ups and that you can turn it on when you are in debug mode?
    Now users can get a pop up that interrupts the app when the programmer forgets to put this in his code.
    If you want to update an app you will have to add this code to the files so it doesn’t start popping up.

    This creates extra work. If it defaults to intercepting and not showing the pop up, nothing changes for the end user and programmers who don’t care.
    Now it is being forced upon us.
    As stated in a previous article on this by the writer. Not all run time errors crash the app or cause any inconvenience. Now they do.

  4. This helps me detect a stack overflow but unfortunately does not give me more info?

    I have working code that was working in Jan 2013 but a newer corona build has broken the widget cant text input destroy code. I rolled back my code to the Jan 2013 code but the new corona crashes

    Maybe I need to roll back to an older corona?

    ——–
    Handling the unhandled error ?:0: stack overflow
    2013-04-11 20:06:25.342 Corona Simulator[1339:707] Runtime error
    ?:0: stack overflow
    stack traceback:
    [C]: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘_cachedRemoveSelf’

    ?: in function ‘_cachedRemoveSelf’
    ?: in function ‘removeSelf’
    ?: in function ‘remove’
    …re/AppsSVN/Removed/widget_candy.lua:1202: in function ‘_RemoveWidget’
    …re/AppsSVN/Removed/widget_candy.lua:593: in function ‘destroy’
    …AppsSVN/Removed/recipecalscreen.lua:1847: in function ‘cleanUp’
    …m Software/AppsSVN/Removed/main.lua:87: in function ‘loadScreen’
    …m Software/AppsSVN/Removed/main.lua:110: in function ‘onRelease’
    …com Software/AppsSVN/Removed/ui.lua:90: in function
    ?: in function

  5. so re returning true or false.. the doco has:

    “If true is returned from the listener for unhandledError then the error is suppressed and application execution will continue. Returning false (or nothing) from the listener will allow the runtime error to be reported to the user and the the application to terminate.”

    So does this imply if you return false (or nothing) the application will continue to behave exactly how it would have if you didn’t implement the handler? So if you had some error in a listeners that was occurring but not crashing the app and the user could still play, then after implementing this error handler system it would be the same, but with the advantage of you had a chance to print it out (or log it to flurry for example)

    This being the case, then the safest approach would be to return false (or nothing) correct?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>