Great template with ES2017 async / await:
async function () {
try {
var result = await some_promised_value()
} catch (err) {
console.log(`This block would be processed in
a reject() callback with promise patterns
but this is far more intuitive`)
return false
}
result = do_something_to_result(result)
return result;
}
The ability to deal with such errors is very good. But I will say that I want to asynchronously get a value that I would like to protect against reassignment (for example, a database session), but I still want to use the async / await pattern (purely because I think it is much more intuitive).
The following actions will not work because const is a block scope:
async function () {
try {
const result = await get_session()
} catch (err) {
console.log(`This block should catch any
instantiation errors.`)
return false
}
}
, try, , . (, , , , , , . , - - , .)
, , . Promises . var const let. .
[question]: try/catch await/async ? , , try/catch. , try/catch , return try/catch, async/await, - .
- const x = await y() catch (err) const x = await y() || fail , .
UPDATE:
@jmar777 , :
const x = await y().catch(() => {})
, , . return, . .
.
let ( jmar777) , , .