Actually, I tend to disagree with the comments made by others.
Far more often than they want to admit it to themselves magicians will get caught, but most spectators are polite enough to keep quiet and let the others enjoy the show. The correct way to handle it partly falls under the heading of "Audience Management". You have to set the expectations right from the very beginning.
IMHO first and foremost you are an
entertainer. You have to make it clear that you are not about to show your spectators that you are smarter than they are and that you can achieve things they cannot. If you setup a challenge, you are very likely to start up a competition and infuriate every single potential heckler and put the rest of the audience on the heckler's side. (Besides, most likely at least some members of your audience ARE smarter than you are!) If, instead, you are showing up as the average Joe, who does not have supernatural skills but just improved natural abilities we all have, you are not seen as a threat to anybody's intellect. This is a lesson I have learned from Richard Osterlind and unfortunately it remains to be one of those secrets of magic that are forgotten over the latest methods and secrets whose exposure allegedly causes so much harm to the art ... but I digress.
Now let's assume you have not upset anybody and have established a positive atmosphere of cooperation. What else can you do to improve your presentation?
First, you have to know your handling. Yes, you knew that already, didn't you?
However, it is not enough to do a sleight in front of a mirror, a camera, surrounded or whatever. You have to be able to do it when you are surrounded by spectators, nervous, talking and gesturing. You do not have to "know a move", you have to "perform your presentation".
During rehearsal, you must plan and practice the gestures, the wording, and the sleights as a unit. If you can do the move only when you stop talking and look straight forward, it will be as useless as if you cannot do it at all. In most cases, it will not be a flash or a shaky handling, but your own body language, your feeling of "guilt" which will give a sleight/gimmick/whatever away. Through this behavior, the audience will know that you did "something", but not necessarily what.
It
will take time to become perfect. And you will also have to fail in your performances (everybody does). Just don't give up to practice. You don't have to know many moves, sleights, tricks or routines. Many magicians became famous with just a single effect. Choose one effect, practice it daily, for several months straight. Keep performing it, figure out what works (meaning, what ENTERTAINS, NOT WHAT FOOLS!!!) for you and keep improving the weak points.
Well, you might still get caught. At least, I do (and sometimes it is because I'm breaking my own rules). For such cases, you may want to prepare and rehearse an "out". See it as a part of your presentation, an alternative path your show can take (but usually does not). I have learned while performing which things can go wrong. I now collect these problems and prepare outs for them. As time passes, it becomes better and better. But when, where and what you need will depend on your personality. A simple "Oops, sorry, I messed that one up!" may go further than the most elaborate gimmick can take you. It shows (see above) that you are as human as your spectators.
You can theorize about problems on your own, but actually what goes wrong during performance will be quite different from what you were afraid of before. There are zillions of threads on hypothetical problems of effects which just are not problematic at all in the real world and only become so because magicians are afraid of it. If you did not encounter something a colleague perceives as a "problem", then most likely it does not exist! So don't be afraid of it. If it causes your performance to be not entertaining on a regular basis, THEN it is the right time to worry!
Sorry for the rather lengthy post, but I hope it helps you a little to find what works best for you. Just don't be discouraged and don't give up. We are all having bad days and the best learning opportunity is form your mistakes.
