It is narrated from Hazrat Anas bin Malik (may Allah be pleased with him) that the Prophet (peace and blessings be upon him) said: None of you should wish for death because of any hardship that befalls 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 grant me death when death is better for me.
Hadith Referenceمسند احمد / مسند المكثرين من الصحابة / 12755
Hadith Gradingحکم دارالسلام:حديث صحيح، خ: 6351، م: 2680، وهذا إسناد ضعيف لضعف علي بن زيد بن جدعان، ولكن تابعه جماعة من الثقات