wintercg / proposal-common-minimum-api

https://common-min-api.proposal.wintercg.org/
Other
216 stars 15 forks source link

How to deal with something like `UncaughtException`? #29

Open XadillaX opened 1 year ago

XadillaX commented 1 year ago

For exceptions from Promise, we can simply use unhandledrejection. But how about exceptions that not come from Promise? Is there any way to specify the behavior?

leizongmin commented 1 year ago

Can you give some examples of exceptions that do not come from Promise?

XadillaX commented 1 year ago
function test() {
  throw new Error('hello');
}

test();
exoticknight commented 1 year ago

maybe use something like

addEventListener('error', fn)
ljharb commented 1 year ago

That would imply, in a browser, an "error" event on the document, I think. Do browsers have an event for this?

XadillaX commented 1 year ago

That would imply, in a browser, an "error" event on the document, I think. Do browsers have an event for this?

https://developer.mozilla.org/en-US/docs/Web/API/Window/error_event

ljharb commented 1 year ago

ah ok, so then it’s already an event on the global - that seems like something that should come for free with event emitters?

XadillaX commented 1 year ago

ah ok, so then it’s already an event on the global - that seems like something that should come for free with event emitters?

I think yes.

Not only for this event. I think we shoud collect and specify all available events in globalScope of Winter.

e.g. install / activate / unhandedrejection / error, etc.

benjamingr commented 1 year ago

In general, I think it's better (standards wise for new platforms) to use onerror/onunhandledrejection and not Node's uncaughtException/unhandledRejection/rejectionHandled hooks (and not ship EventEmitter) but mostly: I don't think it makes a ton of sense to standardize given the different error handling model.

XadillaX commented 1 year ago

Since we're discussing error event, I think ErrorEvent should be added into Common Minium API.

https://html.spec.whatwg.org/multipage/webappapis.html#errorevent

benjamingr commented 1 year ago

Since we're discussing error event, I think ErrorEvent should be added into Common Minium API.

I don't think Node.js is interested in this if we're not shipping globalThis.addEventListener("error" which we are currently not and have no plans to as far as I can tell.

Also, Deno for example does something different from browsers (fires "error" for unhandled rejections).