4 ms·
In JavaScript there are two types of errors: First class errors that you can return, pass around and bubble up. And then there are exceptions that means the pro
by z3t4 7y ago
In JavaScript there are two types of errors: First class errors that you can return, pass around and bubble up. And then there are exceptions that means the program did something unexpecting. Promises make no exception and does not treat them as first class citizens.
- WorldMaker 7y agoPromises make future exceptions. If you aren't paying attention "in the future" to catch those exceptions, they bubble to an error handler (window.onUnhandledRejection [0]), so it acts as both types of JS errors, depending on how you want to pay attention to it. async/await syntax lets you catch promise rejection exactly like you would any other type of JS exception with a try {} catch {}. [0] https://developer.mozilla.org/en-US/docs/Web/API/Window/unhandledrejection_event https://developer.mozilla.org/en-US/docs/Web/API/Window/unha...
- WorldMaker 7y agoTo bring things back on topic: async/await syntax in JS inherits its magic almost directly from Haskell's do-notation and is exactly an example of why exploring Monads has been practically useful for languages far outside of the "academic ivory tower walls" of Haskell.