Abu Hurairah (May Allah be pleased with him) reported
that the Prophet, peace be upon him, said:
'Whoever sees somebody who is sick or in some hardship, and says
the following dua will never be afflicted by that sickness or difficulty:
Alhamndulil laahillazee'aafaanee mimmab-talaaka bihee
wafad dalanee 'alaa kaseerim mimman khalaqa tafdeelaa
{Praise and thanks be to Allah Who has saved me from what he has
afflicted you with, and has honored me over many of His creatures}
(Reported by Tirmizhi, who considers it sound)
An-Nawawi states that the scholars said, "One should say the above
mentioned supplication inaudibly so that the afflicted person should not
hear it, lest he should be grieved by it. But if the affliction is the result
of his sinful conduct then there is no harm in his listening if he is not
heedful of evil."