When you fail, the first step is getting over yourself. Understand that it’s not about you; find out why you failed and work on them. And if there is a task that you must execute, do not focus on the parts that you can do.
You should aim for those that you cannot do because the curiosity to learn how to get something done makes you realize that you can do some things that you never thought you would be able to do.
Also, if you must give up or leave the scene, make sure it is on your terms. Never let circumstances determine your decisions.