All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
Whoever sleeps (and thus is detained) from, or forgets an obligatory prayer, it is due upon him to pray it once he gets up or remembers it, due to the statement of the Prophet, sallallaahu ‘alayhi wa sallam:
Whoever forgets or sleeps (and thus is detained) from offering an obligatory prayer, its expiation is to pray it once he remembers it. [Muslim]
It is well-established among the scholars of Fiqh that this is due immediately.
This applies to the one who got up after the due time of prayer was over. But as for him who got up before the due time of prayer was over and was afraid that if he made Ghusl the due time would be over, Ghusl would be due on him even if it should lead him to miss the due time, according to the majority of scholars.
Maalik however, is of the opinion that he has to perform dry ablution and pray in the due time.
Based on that, let us say:
Should missing the train or the exam lead to trouble or harm, and you get up before the due time of the prayer is over, we see that you should perform dry ablution and pray, acting upon the opinion of Maalik .
But if you get up after the due time of prayer is over, then, we see that you should make Ghusl and pray, given that Ghusl takes only a few minutes. If you have no time and you are afraid that you may miss your purpose, which might cause you harm, then you may perform dry ablution and pray, depending upon the opinion of the Maaliki scholars of Fiqh, that it is permissible to perform dry ablution (instead of Ghusl) when there is fear of missing the company (on a journey). The author of Mawaahib Al-Jaleel said:
Al-Qurtubi said in his Tafseer, "Among the causes of performing dry ablution is the fear of missing the company (on a journey); and this is the predominant opinion; and Allaah The Almighty Knows best."
No doubt, missing a train or an exam might be more harmful than missing the company on a journey.
Allaah Knows best.