Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with something like UncaughtException? #29

Open
XadillaX opened this issue Sep 14, 2022 · 10 comments
Open

How to deal with something like UncaughtException? #29

XadillaX opened this issue Sep 14, 2022 · 10 comments

Comments

@XadillaX
Copy link

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
Copy link

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

@XadillaX
Copy link
Author

function test() {
  throw new Error('hello');
}

test();

@exoticknight
Copy link

maybe use something like

addEventListener('error', fn)

@ljharb
Copy link
Member

ljharb commented Sep 14, 2022

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

@XadillaX
Copy link
Author

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
Copy link
Member

ljharb commented Sep 14, 2022

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
Copy link
Author

XadillaX commented Sep 14, 2022

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants