שולחן ערוך, אורח חיים רכ״ב
Shulchan Arukh, Orach Chayim 222
1ברכת הודאת הטוב והרע. ובו ד סעיפים:על שמועות שהם טובות לו לבדו מברך שהחיינו ואם הן טובות לו ולאחרים מברך הטוב והמטיב:
On news that are good for him, he makes the blessing of "Shehecheyanu"; If the news is good for him and for others, he makes the blessing of "Hatov VehaMaytiv".
2על שמועות רעות מברך בא"י אמ"ה דיין האמת:
On bad news he makes the blessing: Blessed are you Hashem, Our G-d, Master of the Universe, the judge of truth.”
3חייב אדם לברך על הרעה בדעת שלימה ובנפש חפצה כדרך שמברך על הטובה כי הרעה לעובדי השם הוא שמחתם וטובתם כיון שמקבל מאהבה מה שגזר עליו השם נמצא שבקבלת רעה זו הוא עובד את השם שהוא שמחה לו:
A person is obligated to bless on the bad with a full mind and wanting soul, in the way that he blesses happily on the good, because the bad, for servants of G-d, is their happiness and goodness. Since he/she has accepted out of love what G-d has decreed, he/she finds that by accepting this bad, he/she is serving G-d which bring him happiness.
4מברך על הטובה הטוב והמטיב אע"פ שירא שמא יבא לו רעה ממנו כגון שמצא מציאה וירא שמא ישמע למלך ויקח כל אשר לו וכן מברך על הרעה ברוך דיין האמת אע"פ שיבא לו טובה ממנו כגון שבא לו שטף על שדהו אף ע"פ שכשיעבור השטף היא טובה לו שהשקה שדהו:
He blesses on the good: “Hatov Vemaytiv” even though he is fearful that bad might come from Him. For example: He found a “prize” and he is fearful that it may become known to the king and the king will take all that he has. He blesses on the bad: “Blessed Judge of Truth”, even though good will come from Him. For Example: a flood has washed away his field even though when the flood passes, it will be good for him, as the field has been watered.