“By the sacred anointing of the sick and the prayer of the priests the whole Church commends those who are ill to the suffering and glorified Lord, that he may raise them up and save them. and indeed she exhorts them to contribute to the good of the People of God by freely uniting themselves to the Passion and death of Christ” (CCC 1499).
“The anointing of the sick can be administered to any member of the faithful who, having reached the use of reason, begins to be in danger of death by reason of illness or old age” (Can. 1004 §1).
It is very important to call a priest as soon as a Catholic is in danger of death, so they can receive the Sacrament of the Sick and other sacramental graces in their time of need.