Runtime error handling.

Hi,

I wanted to see how to handle run-time errors

The following code does not trap the error.

I just want one specific portion of the code to trap errors.

where am I going wrong?

– catch it 

    local function supressError( event ) 

        print("Suppress error: "…event.errorMessage)

        return true

    end

    

– catch on

    Runtime:addEventListener(“unhandledError”, supressError)

–create error

    local x=nil

    local y=x+1

– turn off catching

    Runtime:removeEventListener(“unhandledError”, supressError)

I get this error, i.e. it was not caught:

menu.lua:748: attempt to perform arithmetic on local ‘x’ (a nil value)