If one hears thundering while in the bathroom and did not use the bathroom, then they should just exit the bathroom and recite the bracha. However, if one did use the bathroom, then they should exit the bathroom, wipe their hands on something, and recite the bracha before they lose the chance. Similarly, if one is in a shul and hears kadish or kedusha before they were able to wash their hands, they should wipe their hands on something and recite along with the tzibbur.