The timeout code is executed outside the promise context. What you want to do is call 'reject' with the error:
const TIMEOUT = 1000;
const mySecondPromise = new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error(`Error in asynchronous function`));
},
TIMEOUT
);
});
mySecondPromise
.catch(() => console.log(`This code WILL be executed`));