function a() {
return new Promise((resolve, reject)=> {
setTimeout(function() { reject('//a') }, 100);
})
}
async function b() {
console.log("await "+ await a())
throw '//b '
console.log("return")
return await a()
}
b().catch(function(val) { console.log(val) })
//OUTPUT:
//a
throw b before await a
function a() {
return new Promise((resolve, reject)=> {
setTimeout(function() { reject('//a') }, 100);
})
}
async function b() {
- console.log("await "+ await a())
throw '//b '
console.log("return")
return await a()
}
b().catch(function(val) { console.log(val) })
//OUTPUT:
-//a
+//b
try only catch when await
b()
// b().catch(function(val) { console.log(val) })
async function c() {
try {
+ await b() // --- (1)
} catch(e) { // --- (2)
throw e + '//[re c]'
}
}
c().catch(function(val) { console.log(val) })
//OUTPUT:
//b //[re c]
async throws native throws imediatyly
async function c() {
+ throw "//c"
try {
await b() // --- (1)
} catch(e) { // --- (2)
throw e + '//[re c]'
}
}
c().catch(function(val) { console.log(val) })
//OUTPUT:
-//b //[re c]
+//c
better have some
new Promise({...})
uncautght
uncautght
caught
_but_
new Promise( _ => 1).then(function(value){
unexpected