I will always remember what Jim Pace said to me when I asked "What do you do when the (invisible thread) string breaks?"He just gave me this weird look and said "It doesn't."
The idea is that it's also important to practice - a lot. To the point where you are confident that things won't go wrong. When you are starting magic, you feel like you can't practice anymore, but keep practicing! Then once you are sure you have it down pat, practice some more!
Practice with a mirror. Record it on your cell phone and watch it back. You will see the mistakes you made and be able to correct them.
This will not only help the trick to go right, but your performance will be better and your nerves will be calmer once you actually perform it.
That said...
Sometimes things go wrong outside of your control.
One time I was at a paid gig performing
Interlace. Well, the ring got 'lost' (I knew where it was) and would not appear on my shoelace. What a mess. Now I have a back up plan if that ever happens again.
Another time I was doing tossed out deck and a person just lied about the card they saw (you can know with that effect). I had to just concede they had "got me' and that sometimes these things aren't always clear. Now for every show, I have a small clear box on stage with an Invisible Deck inside. I set it in full view and have never had to use it. But in the instance someone does that again, I have that as an out.
For impromptu card tricks, I have a couple of tricks I do as an out if I ever lose their card in the deck. My go-to if I am being sloppy an lose a break, I genuinely mix the deck and then talk about how hard it is to actually retrieve a card. Then I hand them the deck and say "try it!" I'll count to see how long it takes. They go through the deck an find their card as fast as they can. I praise them for how fast they were ("Oh wow! Most people take much longer! Nice work! I'm not sure I can top that, but I'll try..." or "If pulling it out takes __ seconds, imagine how easy it would be to find if the cards just floated to the top of the deck.." etc.)
Then I go into the trick that is appropriate.
Usually this or a short three phase ambitious routine.