סימן סא סעיף א
אַרְבָּעָה צְרִיכִים לְהוֹדוֹת. יוֹרְדֵי הַיָּם כְּשֶׁיַּגִּיעוּ לִמְחוֹז חֶפְצָם, וְכֵן הוֹלְכֵי מִדְבָּרִיּוֹת אוֹ בִּשְׁאָר דֶּרֶךְ שֶׁמֻּחְזָק שֶׁיֶּשׁ בּוֹ סַכָּנָה, כְּשֶׁיַּגִּיעוּ לִמְחוֹז חֶפְצָם, וּבִכְלָל זֶה גַּם מִי שֶׁהָיָה בְּסַכָּנָה אַחֶרֶת וְנִצֹּל הֵימֶנָּה, כְּגוֹן שֶׁנָּפַל עָלָיו כֹּתֶל אוֹ נְגָחוֹ שׁוֹר אוֹ שֶׁבָּאוּ עָלָיו לִסְטִים בַּדֶּרֶךְ וְשׁוֹדְדֵי לַיְלָה וְנִצַּל מֵהֶם וְכַדּוֹמֶה, וּמִי שֶׁהָיָה חוֹלֶה שֶׁיֵּשׁ בּוֹ סַכָּנָה, כְּגוֹן מַכָּה שֶׁל חָלָל, אוֹ שֶׁהָיָה מוּטָל בַּמִּטָּה שְׁלשָׁה יָמִים מֵחֲמַת הַחֹלִי וְנִתְרַפֵּא וְהוֹלֵךְ עַל בָּרְיוֹ. וּמִי שֶהָיָה חָבוּשׁ בְּבֵית הָאֲסוּרִים, אֲפִלּוּ רַק עַל עִסְקֵי מָמוֹן וְיָצָא. וְסִימָנְךָ וְכָל הַחַיִּי"ם יוֹדוּךָ סֶלָה, חוֹלֶה, יִסּוּרִים, יָם, מִדְבָּר. מַה מְבָרֵךְ. בָּרוּךְ אַתָּה ה' אֱלֹקֵינוּ מֶלֶךְ הָעוֹלָם, הַגּוֹמֵל לַחַיָּבִים טוֹבוֹת שֶׁגְּמָלַנִי כָּל טוֹב. וְהַשּׁוֹמְעִים אוֹמְרִים, מִי שֶׁגּמָלְךָ טוֹב הוּא יִגְמָלְךָ כָּל טוֹב סֶלָה.
On four [occasions] a person must thank God [for His goodness];1A boy under the age of thirteen does not say Hagomeil. The accepted minhag is that women do not recite this berachah either. The acharonim (authorities of the recent past) offer the reason, that this berachah is recited in the presence of a minyan, which does not apply to women. (Mishnah Berurah 219: 1) 1] after crossing the ocean and reaching his destination; 2] after crossing the desert or any other dangerous road and reaching his destination; included in this rule is also one who was saved from any other peril, as when a wall caved in on him or an ox lunged at him, ready to gore him, or robbers attacked him on the road, or thieves at night and he was saved from them, or from similar perils; 3] one who suffered from serious illness or a serious injury or he was confined to bed for [at least] three days due to an illness and he recovered, his health restored; 4] one who was in prison even if [he was in prison] only because of monetary matters and he was released. [The following phrase may serve as] a mnemonic device: "All those who are alive thank you, selah." [The word chayim—חיים — forms the acronym of] choleh—a sick person, yisurim —a person suffering [in prison], yam—(crossing the) ocean, midbar—(crossing the) desert. What berachah should they say? Baruch ata Adonoy Elokeinu melech ha'olam hagomeil lechayavim tovos shegemalani kol tov, [Blessed are You, Hashem, our God, King of the universe, Who bestows good things upon the guilty, Who has bestowed every goodness upon me]. The listeners should respond: mi shegemalecha tov hu yigmalecha kol tov selah, [May He Who has bestowed goodness upon you continue to bestow every goodness upon you forever].
תנא דבי אליהו כל השונה הלכות בכל יום מובטח לו שהוא בן העולם הבא שנאמר הליכות עולם לו אל תקרי הליכות אלא הלכות (נדה ע"ג.)