Abdullah bin Umar reported,

The Messenger of Allah ﷺ said, "Whoever comes upon a person afflicted with a trial and says, 'Praise be to Allah who has spared me from what He has tested you with and has favored me greatly over many of those whom He has created,' will be protected from that trial, whatever it may be."

Ibn Majah 3892

Daif

حدثنا علي بن محمد حدثنا وكيع عن خارجة بن مصعب عن أبي يحيى عمرو بن دينار وليس بصاحب ابن عيينة مولى آل الزبير عن سالم

عن ابن عمر قال

قال رسول الله ﷺ من فجئه صاحب بلاء فقال الحمد لله الذي عافاني مما ابتلاك به وفضلني على كثير ممن خلق تفضيلا عوفي من ذلك البلاء كائنا ما كان

ابن ماجه 3892ضعيف
Contents
Reference
Commentary
Ayat
Collection
Sunan Ibn Majah
Book
Supplication
Chapter
What a man should say when he sees people afflicted with calamity
Numbering
Darussalam 3892
Ibn Majah 3892