I agree with Nishant, above. I would like to add that in his book Preparation for Death, St. Alphonse de Liguori mentions final perseverance in several places, each time building up the concept, until near the end of the book he explains that while this greatest of all graces is not something that can be earned by merit, it can nonetheless be obtained "as if by supplication," for after a lifetime of praying for it, a penitent sinner would not be refused in his last hour provided he continues to cooperate with God's grace.
In my own experience it has become clear to me that anyone who waits until the end of their life to start asking for the grace of perseverance is making a big mistake. As with the practice of penance, it is much too late to START learning to practice it when a crisis arrives. When we are faced with a disaster our immediate inclination is to do what we have habitually done throughout our life, and if we are not in the habit of making each inconvenience and hardship an act of reparation for sins (our own and others as well) and a sacrifice of penitential suffering offered to God, then the moment of disaster is, humanly speaking, a case of impossibility to overcome this bad habit.
I had kidney stones, on two occasions. Both times I ended up in the hospital, and both times I had the same experience. While I lay on the gurney in the ER, with a morphine drip making me sick to my stomach, every time I made a prayer of offering up the pain, immediately the pain INCREASED. I figured this was the devil trying to punish me for my voluntary act of expiation. Later I told a priest about this and he told me this was just like Our Lord's suffering while hanging on the cross. (He was talking about the increase of pain, not saying that kidney stones are as painful as crucifixion is.) Now, if I had not been practicing for years before that, following the message of Our Lady of Fatima and Catholic Tradition, I can't imagine that I would have been able to START making pain a sacrificial offering to God while enduring the excruciating pain of kidney stones.
Anyone with experience in caring for the elderly may be able to say they have seen some patients seemingly able to endure pain by practicing prayer, and other patients who want nothing to do with prayer seem to suffer a lot more. But just try to get such a patient who wants nothing to do with prayer to start praying while they're suffering pain, and you'll have a losing battle on your hands. The obvious reason is that they experience the pain getting WORSE every time they start to pray, and since they're not accustomed to prayer, they then see prayer as the CAUSE of their pain, and therefore want even LESS than nothing to do with it.
This all applies directly to final perseverance because the final agony of death is the time when we need to ALREADY be in the habit of perseverance, not just then giving it a first try.
.