Before one recites a brachah it is important to know which brachah one is about to recite, so that when they recite Hashem’s name, they are aware of the brachah it is going on. However, even if one did not know which brachah they planned to recite until after they said the name of Hashem, b’dieved they do not need to repeat the brachah. For example, if one was holding a cup and thought that it is wine and after saying “Hashem” realizes that it is beer, (and now instead of ending with borei pri hagefen has to end with shehakol,) should end with shehakol.