5 ms·
_any_ function that returns a promise should have the `async` modifier - even if `await` isn't used. A function may return a promise or throw an exception. An
by seniorsassycat 7y ago
_any_ function that returns a promise should have the `async` modifier - even if `await` isn't used.
A function may return a promise or throw an exception. An `async` function may only return a promise. async functions cannot throw exceptions.
```
// This code sucks but you might have to write it if `get` isn't an async function.
try {
get().catch(_ => /* handle async errors /)
} catch {
/ handle sync errors */
}
```
- majewsky 7y agoHN does not support the Markdown syntax for code blocks. You need to indent all lines by two spaces to get a code block.
- matt-attack 7y agoInteresting about adding async. I actually didn’t know it eliminated the possibility of it throwing an error. What happens if it explicitly throws an error?
- seniorsassycat 7y agoAn async function that throws and error will return a promise that will reject with the thrown error.