The basic doctrine is "Extra Ecclesiam nulla salus:" outside the Church there is no salvation.
This is formulated by St. Cyprian in Epistle 72 (emphasis mine):
But if not even the baptism of a public confession and blood can profit a heretic to salvation, because there is no salvation out of the Church, how much less shall it be of advantage to him, if in a hiding-place and a cave of robbers, stained with the contagion of adulterous water, he has not only not put off his old sins, but rather heaped up still newer and greater ones!
And affirmed by about a dozen Popes in the form of ecumenical councils, encyclicals, and papal bulls. But the line has been prone to misinterpretation, and it's a lot more complicated than it appears.
The Catechism of the Catholic Church says this on the matter:
846How are we to understand this affirmation, often repeated by the Church Fathers? Re-formulated positively, it means that all salvation comes from Christ the Head through the Church which is his Body:
Basing itself on Scripture and Tradition, the Council teaches that the Church, a pilgrim now on earth, is necessary for salvation: the one Christ is the mediator and the way of salvation; he is present to us in his body which is the Church. He himself explicitly asserted the necessity of faith and Baptism, and thereby affirmed at the same time the necessity of the Church which men enter through Baptism as through a door. Hence they could not be saved who, knowing that the Catholic Church was founded as necessary by God through Christ, would refuse either to enter it or to remain in it.
847 This affirmation is not aimed at those who, through no fault of their own, do not know Christ and his Church:
Those who, through no fault of their own, do not know the Gospel of Christ or his Church, but who nevertheless seek God with a sincere heart, and, moved by grace, try in their actions to do his will as they know it through the dictates of their conscience - those too may achieve eternal salvation.
The issue is something called "inculpable ignorance." The Catholic Church is the only path to salvation, but those who do not know its dogmata through no fault of their own are to be held blameless: they will not be punished for that which they do not know is wrong, and can still be saved through the Church:
848"Although in ways known to himself God can lead those who, through no fault of their own, are ignorant of the Gospel, to that faith without which it is impossible to please him, the Church still has the obligation and also the sacred right to evangelize all men."
But those that do know the Catholic faith and reject it cannot be saved: there is no alternate path to salvation. From the Lumen Gentium (LG), paragraph 14:
In explicit terms He Himself affirmed the necessity of faith and baptism and thereby affirmed also the necessity of the Church, for through baptism as through a door men enter the Church. Whosoever, therefore, knowing that the Catholic Church was made necessary by Christ, would refuse to enter or to remain in it, could not be saved.
But, it's still a little more complicated than that. This doctrine, as explained above, might be interpreted to mean that only non-Christians that are also ignorant of the Catholic faith are held blameless. But it also applies to Christians. From the Unitatis Redintegratio, paragraph 3:
Even in the beginnings of this one and only Church of God there arose certain rifts, which the Apostle strongly condemned. But in subsequent centuries much more serious dissensions made their appearance and quite large communities came to be separated from full communion with the Catholic Church-for which, often enough, men of both sides were to blame. The children who are born into these Communities and who grow up believing in Christ cannot be accused of the sin involved in the separation, and the Catholic Church embraces upon them as brothers, with respect and affection. For men who believe in Christ and have been truly baptized are in communion with the Catholic Church even though this communion is imperfect.
That is, what's interesting about this doctrine is that it essentially puts nearly every Christian denomination in partial communion with the Church: nearly all Christians agree with the Roman Catholic Church on some things. If they never learn anything about the things with which they disagree (to give a basic example, the prohibition on the priestly ordination of women), they would be held blameless.
It's only when a Christian is faced with both the Catholic position and the non-Catholic position—and chooses the latter—that it becomes a problem of heresy. They could do this for any number of reasons: misinformation, misinterpretation, reliance on bad actors, etc. It's then the mission of the Church to bring those people back into the fold. From LG., paragraph 16:
But often men, deceived by the Evil One, have become vain in their reasonings and have exchanged the truth of God for a lie, serving the creature rather than the Creator. Or some there are who, living and dying in this world without God, are exposed to final despair. Wherefore to promote the glory of God and procure the salvation of all of these, and mindful of the command of the Lord, "Preach the Gospel to every creature", the Church fosters the missions with care and attention.