Comments (4)
@kettanaito Thank you!
from until.
@kettanaito I think this might be incorrect - await
should throw on promise rejection
In your example you're just missing an await
- add it and console.log
is called:
try { await new Promise(() => { throw new Error('Hey') }) } catch (e) { console.log(e) }
from until.
@terenced can you tell me why?thank you
from until.
The .catch()
block was added to propagate unhandled exceptions to the library.
When there's an exception thrown during a Promise, it will not be caught by a try/catch
block around it:
try { new Promise(() => { throw new Error('Hey') }) } catch (e) { console.log(e) }
The
console.log
will never be called. The thrown exception will be printed as anUnhandledPromiseRejectionWarning
.
Flow-wise, that is still an unsuccessful promise execution, so this library should execute the return [error, null]
closure for the dependent code to handle it like an error. Adding an explicit .catch()
statement to the given promise catches any errors occurring in that promise.
This solution also doesn't interfere with you defining your custom .catch()
, as catch doesn't have an accumulative nature. If you've defined your custom .catch()
block, it will get executed first, and the library's .catch()
will not, unless you throw another exception in your own catch block.
new Promise(() => { throw new Error('Hey') }).catch(e => console.log('Custom', e)).catch(e => console.log('Library', e))
from until.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from until.