Is it possible for a person with a mortal sin still on his soul to die and go to heaven?
No. “To die in mortal sin without repenting and accepting God’s merciful love means remaining separated from him forever by our own free choice” (CCC 1033). But it is important to understand what constitutes a mortal sin and the ways mortal sin can be forgiven.
In order for a sin to be mortal, three conditions must be met: (1) The sin must have grave matter, (2) one must have adequate knowledge that it is a grave offense, and (3) one must commit the offense with deliberate consent (CCC 1857–1859). If one of these conditions is not met, the sin will be venial, not mortal.
There are two kinds of sorrow for sin: contrition and attrition, which are called also perfect contrition and imperfect contrition. Perfect contrition does not mean the perfectdegree of contrition, but the perfect kind of contrition—that is, sorrow for sins based on charity, or supernatural love of God. Imperfect contrition is sorrow for sin based on anything other than charity (such as being sorry for our sins because we fear the punishment of hell and God’s wrath).
Perfect and imperfect contrition are not mutually exclusive. A person can have both at the same time. Both perfect and imperfect contrition assume the resolve to sin no more. Even with this resolve, it is possible to commit the same sin in the future. What is important is that at this moment in time we make a firm resolution to turn away from mortal sin.
Under normal circumstances, for a mortal sin to be forgiven, it must be confessed in the sacrament of penance. If the penitent has perfect or imperfect contrition for his sin, confesses all his mortal sins since his last good confession, resolving not to commit the sin again, and receives absolution from the priest, his mortal sins are forgiven.
What happens if confession to a priest is impossible, and one is close to death or in danger of dying? Provided a person, finding himself in this situation, has perfect contrition for his mortal sins, and resolves not to sin again and receive sacramental confession as soon as possible, his mortal sin is forgiven. Imperfect sorrow is not contrition under these circumstances.