Promise chain continues after rejection

I’m having trouble to properly catch an error/reject in a promise chain.

const p1 = () => {
    return new Promise((resolve, reject) => {
        console.log("P1");
        resolve();
    });
};

const p2 = () => {
    return new Promise((resolve, reject) => {
        console.log("P2");
        reject();
    });
};


const p3 = () => {
    return new Promise((resolve, reject) => {
        console.log("P3");
        resolve();
    });
};

p1().catch(() => {
    console.log("Caught p1");
}).then(p2).catch(() => {
    console.log("Caught p2");
}).then(p3).catch(() => {
    console.log("Caught p3");
}).then(() => {
    console.log("Final then");
});

When the promise is rejected, the following .then still gets executed. In my understanding, when in a promise chain an error/reject happened, the .then calls that follow it are not executed any more.

P1
P2
Caught p2
P3
Final then

The rejection gets caught correctly, but why is "P3" logged after the catch?

What am I doing wrong?

To clarify @evolutionxbox, this is my expected result:

Promise.resolve().then(() => {
    console.log("resolve #1");
    return Promise.reject();
}).then(() => {
    console.log("resolve #2");
    return Promise.resolve();
}).then(() => {
    console.log("resolve #3");
    return Promise.resolve();
}).then(() => {
    console.log("Final end");
}).catch(() => {
    console.log("Caught");
});

This code works exactly like it should. And I can’t see a difference to my code, except that I declared the functions separately.

The code above stops no matter where the promise is rejected.

169 thoughts on “Promise chain continues after rejection”

  1. Thanks , I have recently been looking for info approximately this topic for ages and yours is the greatest I’ve found out till now. But, what about the conclusion? Are you sure in regards to the source?

    Reply
  2. hi!,I like your writing very so much! proportion we communicate more about your article on AOL? I require a specialist in this area to solve my problem. May be that is you! Looking ahead to peer you.

    Reply
  3. I am curious to find out what blog system you happen to be working with? I’m having some small security issues with my latest blog and I’d like to find something more risk-free. Do you have any recommendations?

    Reply
  4. Great post. I was checking continuously this blog and I’m impressed!
    Very helpful info particularly the last part 🙂 I care for such
    information much. I was looking for this particular info for a long time.
    Thank you and good luck.

    Reply
  5. İlgini çekebilir: Kaşar kız numaraları İstanbul Boşalma Numaraları Canlı Sohbet Numaraları Sex Hatları Sex NumaralarıBaştan aşağıya sizi zevkten hazza boğacak kadınlarla birlikte kısa ya da uzun bir vakit geçirmek isterseniz eğer onların numaralarına en kısa yoldan bu site üzerindeki numaralara tıklayarak erişebilirsiniz Doymayan Dullar Sıcak Sohbet Hattı https://notepin.co/shared/gaqzedq chat yapın.

    Reply
  6. Hi there! This post could not be written any better! Reading this post
    reminds me of my previous room mate! He always kept talking
    about this. I will forward this write-up to him.
    Pretty sure he will have a good read. Thanks for
    sharing!

    Reply
  7. İlgini çekebilir: Telefonda sohbet edecek bayanlar Dul Sohbet HattıKadınlarla özel hatlardan özel anları paylaşmak isteyen diğer erkekler gibi siz de sayfada kadınların numaralarına yada resimlerine tıklayarak Kadın numaraları sohbet hattında boşalmaya başlayabilirsiniz Dul Sohbet Hattı http://uid.me/trsohbet_mobi chat yapın.

    Reply
  8. Looking at this article, I miss the time when I didn’t wear a mask. totosite Hopefully this corona will end soon. My blog is a blog that mainly posts pictures of daily life before Corona and landscapes at that time. If you want to remember that time again, please visit us.

    Reply

Leave a Comment