TiLogCatcher icon indicating copy to clipboard operation
TiLogCatcher copied to clipboard

Prevent loop

Open FokkeZB opened this issue 10 years ago • 4 comments

If the code in the listener creates another JS error, you'll get in a loop. Would there be a way for the module to prevent this?

Workaround is to use try/catch in the listener of course :)

FokkeZB avatar Feb 20 '15 14:02 FokkeZB

Can you give me an example that will cause it?

dbankier avatar Feb 21 '15 21:02 dbankier

Sure:

require("yy.logcatcher").addEventListener('error', troubleMaker);

var win = Ti.UI.createWindow({
  backgroundColor: 'white'
});

var btn = Ti.UI.createButton({
  title: 'Click Me'
});

btn.addEventListener('click', troubleMaker);

win.add(btn);

win.open();

function troubleMaker() {
  JSON.parse('foo');
}

FokkeZB avatar Feb 22 '15 06:02 FokkeZB

That deserves an infinite loop. PR?

dbankier avatar Feb 22 '15 21:02 dbankier

That's why it's a good use case, but of course in real world the problem is edge cases where depending on the error, and external factors influencing how it's handled that you'd run into the loop.

I'm not much good in Obj-C/JAVA I'm afraid. And since it's an edge case, I don't need it to be fixed soon. Just let this ticket sit here so we are aware ;)

FokkeZB avatar Feb 23 '15 06:02 FokkeZB