Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1057] iOS: Exceptions failing in event listeners

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-07-25T12:43:24.000+0000
Affected Version/sRelease 1.5.0
Fix Version/sn/a
ComponentsiOS
Labelsn/a
Reporterctredway
AssigneeNeeraj Gupta
Created2011-04-15T02:42:45.000+0000
Updated2012-07-26T22:25:12.000+0000

Description

a customer has reported that if there is a coding issue (i.e. missing var) in an event listener, that error fails to be registered in Developer. Following code shows this behavior.

var i=0;
i.missingMethod();

appropriately logs the exception but

btn.addEventListener('click', function() {
var i=0;
i.missingMethod();
});

does not.

Comments

  1. Stephen Tramer 2011-04-15

    This is a threading issue, certainly. We don't catch and report exceptions that occur on some threads.

  2. Damien Elmes 2011-04-15

    I hit this issue so often that I don't call addEventListener() directly anymore, and instead use:

       var listen = function(obj, event, cb) {
           obj.addEventListener(event, function (e) {
                                    try {
                                        cb(e);
                                    } catch (err) {
                                        alert("Error in callback: " + err);
                                    }
                                });
       };
       
  3. Matthew Lieder 2011-04-15

    That's a great idea Damien; I'm embarrassed I never even thought of doing that. Keep forgetting how flexible Javascript is. Thanks! That'll be a great duct-tape bandage until they fix this.

  4. David Rodriguez 2011-12-18

    Is there any way to do a stack trace with a try and catch?
  5. Stephen Tramer 2012-07-25

    Cannot reproduce described issue in SDK 2.2.0.f9e938d with iPhone Sim 5.1.
       var i=0;
       i.missingMethod();
       
       appropriately logs the exception but
       
       btn.addEventListener('click', function() {
       var i=0;
       i.missingMethod();
       });
       
    This logs information in the console indicating an exception has occurred.

JSON Source