The Catholic Church traditionally taught that only those who were believers and members of the Catholic Church could be saved. There was no salvation for those outside of the Church.
The Council of Florence, 1441, stated that
The most Holy Roman Church firmly believes, professes and preaches that none of those existing outside the Catholic Church... can have a share in life eternal...
Pope Pius IX in his encyclical letter (1863) said that
Well known is the Catholic teaching that no one can be saved outside the Catholic Church. This refers to the belief that only those who are in full communion with the Catholic Church and accept the teachings and magisterium of the Church can be saved.
However, Pope Pius goes on to state that even people who are ignorant to the faith can achieve eternal life, as long as they live moral lives and follow the natural law as set out by God. God will not condemn those who have not committed a deliberate sin.
This statement by Pope Pius was further explained by the Second Vatican Council. It was made clear that although salvation can only come through Christ Jesus and the Catholic Church (of which Jesus is the Head), people outside of the Church can also achieve salvation. This does not mean that the Church should stop all its work though. It means that the Church’s mission to educate others about Christ is more important.
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.CCC 847 (Catechism of the Catholic Church)