Let\'s say I have a set of Promise
s that are making network requests, of which one will fail:
// http://does-not-exist will throw a TypeError
va
Similar answer, but more idiomatic for ES6 perhaps:
const a = Promise.resolve(1);
const b = Promise.reject(new Error(2));
const c = Promise.resolve(3);
Promise.all([a, b, c].map(p => p.catch(e => e)))
.then(results => console.log(results)) // 1,Error: 2,3
.catch(e => console.log(e));
const console = { log: msg => div.innerHTML += msg + "
"};
Depending on the type(s) of values returned, errors can often be distinguished easily enough (e.g. use undefined
for "don't care", typeof
for plain non-object values, result.message
, result.toString().startsWith("Error:")
etc.)