I've found that if you are open to the idea of improvising when you perform, rather than displaying your nervousness about something going wrong, then you will naturally move in that sort of direction. So when something goes wrong, if you perhaps spend a second or two considering what you could do rather than apologising, you'll strike gold at one point, if you do it a lot, your experience will fill the gaps and it will become second nature and seamless. Sometimes this even creates better moments, for example recently I was doing magic at a party and while I held out the deck for the spec to place their card into, another spectator put the card he was still holding from previously on top of it, as I had my head turned I didn't notice at the time.
So I continued on with the effect and at one point near the end, out of guilt I guess one of the spectators told me what happened, I guess they could tell it was reaching a peak and didn't want to embarrass me, I don't know. But without skipping a beat I realised that because of the control I used, the card they placed into the deck while I didn't know, was face up in the deck one spec had been holding the whole time, and the other selected card I was holding in my hand, I knew the locations of the cards and revealed them with a bit of flair and it actually enhanced the reactions I think because they were expecting me to fail, but rather I seemed, to them, effortlessly overcome the issue using magic.
That is one particularly lucky moment where all the moons happened to align for me, but if you are open to it, you can create some truly awesome, and even more impossible moments. Even as simple as if you do multiple effects in a row, with different cards, at one point they will select the same card twice, completely fairly, play it off, gets a great reaction, I've had this happen 4 or 5 times before.