Sometimes you just can't win all the things the way you want. But then even if you fail, there's always a way out from negative things or thoughts getting into your brain or mind because of that failure.
One needs to develop a "learning from failures" attitude. I believe everyone is a student until their last breath and one must keep learning from failures either of someone else's failures or from failures of own.
When one develops a habit rather I would say the hobby of learning from failures, one gets to know the different ways of "how not to" do things while trying to achieve a particular thing one was or while trying to achieve.
So, keep learning and keep tackling! Always remember, "it's okay to fail unless you don't stop learning."
Chintan Kharade