The Code of Canon Law states: “A person who is conscious of grave sin is not to celebrate Mass or receive the body of the Lord without previous sacramental confession unless there is a grave reason and there is no opportunity to confess” (CIC 916). In this canon, what constitutes “grave reason” and what is understood as “no opportunity to confess”?
The New Commentary on the Code of Cannon Law explains what may be considered “grave reason” and “no opportunity to confess”:
Grave reasons for going to communion without confessing include danger of death and serious embarrassment if Communion is not taken. Lack of opportunity to confess includes absence of a confessor, inability to approach the confessor at a scheduled time for the sacrament, and the availability only of a confessor who is known personally and who cannot be approached without embarrassment. (1111)
Keep in mind that a person in such a situation must still make an act of perfect contrition which includes the resolution of confessing as soon as possible. Also, understand that “celebrate Mass” is what the priest does; a person who is conscious of grave sin but does not have “grave reason” and “no opportunity to confess” may still attend Mass—in fact, ordinary obligations to attend Mass remain—but must forego receiving the Eucharist.