As in synchronous code:
try { throw new Error(); } catch(e) { console.log("Caught"); } console.log("This still runs");
The code that runs after the exception is processed will be launched - this is because exceptions are a mechanism for error recovery. By adding this catch, you indicated that the error was handled. In the synchronous case, we deal with this by reorganizing:
try { throw new Error(); } catch(e) { console.log("Caught"); throw e; } console.log("This will not run, still in error");
Promises work similarly:
Promise.reject(Error()).catch(e => { console.log("This runs"); throw e; }).catch(e => { console.log("This runs too"); throw e; });
As a hint, never fail with Error , as you lose a lot of useful things, such as meaningful stack traces.
source share