You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use case. The goal is to stop code execution that follows try/catch, if the try/catch has an error. But it executes.
let urls = ["url", "url", "url"]
co(function* () {
let promises = urls.map(url => {
return request_promise(url);
})
// so x is an array with results from request
let x = yield promises; // x[]
// suppose if JSON.parse(x) throws an error
let j;
try {
j = JSON.parse(x);
}
catch(e) {
// HOW DO I PASS THIS ERROR ON to .catch() block of this generator?
// the code below this try/catch doesn't have to be executed and .then block doesn't have to called
???
}
// I have code here too
// And I don't want it to execute if try/catch throws an error
// but it however executes
... do some stuff with x
return { some_result: foo };
})
.then(result => {
// this block shouldn't execute it try/catch has error, but it does. why?
res.send(200).json(result)
})
.catch(err => {
// the error from try/catch has to be passed on here
res.send(500).json({err: err})
})
The text was updated successfully, but these errors were encountered:
Do I oversee something here?
The normal JS behavior: If you "catch" an exception, it is resolved and normal execution goes on.
Just add another "throw e" in your "catch" block or don't "try/catch" at all.
Does this help?
Use case. The goal is to stop code execution that follows try/catch, if the try/catch has an error. But it executes.
The text was updated successfully, but these errors were encountered: