slightlyoff / Promises

DOM Promises IDL/polyfill
Apache License 2.0
154 stars 28 forks source link

No practical way to handle uncaught exception #61

Closed cowwoc closed 11 years ago

cowwoc commented 11 years ago

The latest version of Promise places the done() method with catch(). The problem is that under Google Chrome you cannot do the following:

futureInstance.catch(error)
{
  window.onerror(error);
}

because window.onerror is undefined, and you cannot throw error; because the Promise will catch the error and translate it into a Promise.reject() which is never handled.

In short, there is no practical way to cause errors to bubble up to the browser's default exception handler. Yes, I can log the error myself but I should be able to push exceptions to the default handler.

domenic commented 11 years ago
promise.catch(function (error) {
   setTimeout(function () { throw error; }, 0);
});
cowwoc commented 11 years ago

@domenic

Thank you. Is it possible to add this to the documentation or add throwUncaughtError() to the API?

sicking commented 11 years ago

A more generic solution might be to add a reportUnhandledError() function somewhere globally.

domenic commented 11 years ago

+1 to @sicking. Related: http://lists.w3.org/Archives/Public/www-dom/2013AprJun/0188.html

@cowwoc I'll leave any documentation changes to @slightlyoff. I'm not sure he intended this polyfill to be actually used in production, more than as a proof of concept. If it's the former, there's surely a lot of work to do.

neonstalwart commented 11 years ago

@domenic "high-fidelity polyfill" tends to give the impression that this might be intended as code that could be used in production. if that's not the case then that wording should probably be toned down a little.