Skip to content

OutputNot attempted

catch, rethrow, recover

Promise.reject(new Error('x'))
.then(() => console.log('t1'))
.catch((e) => {
console.log('c1', e.message);
throw new Error('y');
})
.then(() => console.log('t2'))
.catch((e) => console.log('c2', e.message))
.then(() => console.log('t3'));

Spaces and quote style don’t matter · write a thrown error as TypeError

Ctrl Enter
Show answer & explanation

The expected output comes from actually running the snippet; opening this shows it next to the explanation.

.then without a rejection handler is skipped while the chain is rejected. A catch that throws makes the chain rejected again; a catch that returns normally recovers it, so t3 runs.