phoboslab / Ejecta

A Fast, Open Source JavaScript, Canvas & Audio Implementation for iOS
2.81k stars 322 forks source link

How to catch global Error in JS ? #590

Open finscn opened 8 years ago

finscn commented 8 years ago

Like title says.

as same as window.onerror in Browser

Thanks.

phoboslab commented 8 years ago

What's your use case? I thought window.onerror is considered bad practice nowadays.

It could be added to the EJJavaScriptView's logException method, calling a function on the windowEventsDelegate. But we can't use Ejecta's usual triggerEvent function for this, because window.onerror expects some more parameters instead of just an event object. See https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror#window.onerror

I'm not a fan :/

finscn commented 8 years ago

Sometimes, an uncaught exception will make the game be frozen , I hope the game could be reload or do something else .