סימן ו סעיף ד
צְרִיכִים לִזָּהֵר שֶׁלֹּא לְבָרֵךְ חַס וְשָׁלוֹם בְּרָכָה לְבַטָּלָה, אוֹ לִגְרֹם לְעַצְמוֹ לְבָרֵךְ בְּרָכָה שֶׁאֵינָהּ צְרִיכָה. וְאִם נִכְשַׁל וּבֵרַךְ בְּרָכָה לְבַטָּלָה, וְכֵן בְּעִנְיַן אַחֵר אִם נִכְשַׁל וְהוֹצִיא שֵׁם שָׁמַיִם לְבַטָּלָה, יֹאמַר אַחֲרֶיהָ, בָּרוּךְ שֵׁם כְּבוֹד מַלְכוּתוֹ לְעוֹלָם וָעֶד. וְאִם מִיָּד לְאַחַר שֶׁהִזְכִּיר אֶת הַשֵּׁם נִזְכַּר שֶׁאֵינוֹ צָרִיךְ לְבָרֵךְ, יְסַיֵּם, לַמְּדֵנִי חֻקֶּיךָ, שֶׁזֶּהוּ פָּסוּק שָׁלֵם, וַהֲוֵי כְּמוֹ לִמּוּד וְלֹא לְבַטָּלָה. וְאִם הִתְחִיל גַּם תֵּבַת אֱלֹהֵינוּ וְנִזְכַּר מִיָּד לְאַחַר שֶׁאָמַר אֱלֹהֵי וְלֹא גָמַר לוֹמַר נוּ, יְסַיֵּם וְיֹאמַר, יִשְֹרָאֵל אָבִינוּ מֵעוֹלָם וְעַד עוֹלָם (שֶׁזֶּהוּ גַם כֵּן לְשׁוֹן הַפָּסוּק בְּדִבְרֵי הַיָּמִים א כט). וּמִכָּל מָקוֹם יֹאמַר גַּם בָּזֶה, בָּרוּךְ שֵׁם כְּבוֹד מַלְכוּתוֹ לְעוֹלָם וָעֶד (צל"ח ברכות דף לח).
You must be careful never to recite a berachah in vain God forbid, or cause yourself to recite a berachah which is unnecessary. If you recited a berachah in vain, or if you uttered the Name of Hashem in vain, you should immediately say: Boruch sheim kevod malchuso le'olam va'ed ["Blessed [is His] Name, Whose glorious kingdom is forever and ever."] If immediately after pronouncing Hashem's Name you remember that the berachah is unnecessary, you should conclude [with]: lamdeini chukecha, (teach me Your laws),10Psalms 119:12 the complete verse is בָּרוּ אַתָּה ה׳ לַמְדֵנִי חוּקֶךָ. which is a complete verse. Thus it is considered as learning [Torah] and [the Name] was not mentioned in vain. If you began the word Elokeinu [our God], and immediately recall after saying Elokei and have not said the suffix nu you should conclude by saying: Yisrael Aveenu meolam ve'ad olam [Israel our father forever and ever]11The berachah is now a Scriptural verse which reads Blessed are you God, God of Israel, our Father, forever and ever. (which is also the syntax of a verse in Chronicles I, Chapter 29). Nevertheless you should also say: Boruch sheim kevod malchuso le'olam va'ed (See Tzlach, Maseches Berachos, Page 39).
תנא דבי אליהו כל השונה הלכות בכל יום מובטח לו שהוא בן העולם הבא שנאמר הליכות עולם לו אל תקרי הליכות אלא הלכות (נדה ע"ג.)