1717 صحيح حديث أَنَسٍ رضي الله عنه، قَالَ: قَالَ رَسُولُ اللهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: لاَ يَتَمَنَّيَنَّ أَحَدٌ مِنْكُمُ الْمَوْتَ لِضُرٍّ نَزَلَ بِهِ فَإِنْ كَانَ لاَ بُدَّ مُتَمَنِّيًا لِلْمَوْتِ، فَلْيَقُلِ اللهُمَّ أَحْيِنِي مَا كَانَتِ الْحَيَاةُ خَيْرًا لِي وَتَوَفَّنِي إِذَا كَانَتِ الْوَفَاةُ خَيْرًا لِي
Hazrat Anas (may Allah be pleased with him) narrated that the Messenger of Allah (peace and blessings be upon him) said: None of you should wish for death because of any harm that has befallen him. If wishing for death becomes necessary, then he should say: "O Allah, keep me alive as long as life is better for me, and cause me to die when death is better for me."