Sometimes failing turns out to be the best thing that ever happened.

Of course, it may not feel like that in the moment. When you don't get a promotion you hoped for, and maybe even deserved, it can be crushing. Failing to get the job you wanted can be as painful as a bad breakup, but in the long run it can be a learning opportunity.

If you don't get a promotion you had hoped for, it's OK to have a brief period of mourning. Cry, scream, punch a pillow, and do whatever else you need to do to release the frustration. Do it quickly, though, and don't dwell on your misery.

Instead, let it go, get back up, and try to figure out what happened. Failing isn't fun, but how we fail and what we do next decides whether a single defeat is a blip on the road or a setback that drags you down for good.

Here's more on the matter from our Foolish investors. 

A man hides under a laptop with his hands folded on top.

It's OK to mourn not getting a promotion, but don't dwell on it. Image source: Getty Images.

It's time to reflect 

Selena Maranjian: A key thing to do when you're passed over for a promotion is to give the situation some thought. Ask yourself what happened, why you didn't get the promotion, and what you should do now.

You may never know exactly why you didn't get it -- and it's helpful to not make up reasons, such as the boss doesn't like me, or I'll never advance at this company. There may be good reasons you just are not aware of. For example, perhaps well-meaning and insightful managers see you as great management material but also see that you're not quite ready.

What should you do about the fact that you were passed over? Well, don't just sulk and pout. And don't show anger, either. None of that is very professional, and professionalism is a helpful characteristic when getting promoted.

You'll need to be well thought of by your superiors, too, and being seen as angry and resentful is not a recipe for success. Indeed, getting your boss on your side is very helpful in getting ahead. You might win your boss's favor by being great at what you do, which can reflect well on him or her, too.

Ask your boss why you didn't get it and how you might best position yourself for a future promotion. Find out which of your skills or performance areas need a little improvement. Make it clear that you're interested in working toward a promotion. Perhaps come to a mutual understanding of goals to meet to put you in position for a promotion.

Promotions aren't always fair

Maurie Backman: Back when I worked for a marketing company, I was in line for a promotion that, according to what I'd been led to believe, was mine for the taking. Case in point: My manager at the time, though not the hiring manager for the role, basically told me the job was mine if I wanted it. I was therefore pretty shocked to find out that at the last minute, the hiring manager stepped in and gave the role to one of her direct reports -- someone who, in my humble opinion, was far less qualified and, frankly, less worthy.

I sulked about it for a while, and even let my displeasure be known. Shortly thereafter, I learned that one of the main reasons my colleague had gotten that promotion was that the manager who was ultimately in charge simply knew him better, and didn't want to take a chance on someone she hadn't worked with as extensively -- even though my own manager had vouched for competence, and then some.

It was then that I learned a valuable lesson: Promotions aren't always fair, so if you can't get over the fact that you were passed over for one, you may want to move on. The last thing you want is to get stuck in a dead-end job, and if you need to take your talent elsewhere to have it duly recognized, so be it.

Sometimes it is you

Daniel B. Kline: Early in my career I was driven and hardworking, but not a great colleague. I did my job well and went above and beyond expectations, but I took little care to make sure I wasn't stepping on toes while I did it.

When promotions came up, I always assumed I would get it because I was the best and hardest worker. In some companies that may have been enough, but I was lucky enough to have bosses who understood that being good at your job is one factor in deciding who gets promoted, but not the only one.

Working well with others and making the whole team stronger was also important, and those were skills I lacked. Not getting promotions (at least a few) slowly showed me that I needed to develop skills beyond doing the actual job.

Perhaps the most-telling moment was when my boss at the summer camp I worked at for six years gently told me I would probably not get a job I wanted the next summer.

"If I could pick anyone to work with on a job, it would be you," he said. "But I'm not sure you would be my first choice to be in charge of anything."

At the time I was probably happy about the first part of his statement, and offended by the second. Over the years, however, as disappointments piled up, I often reflected back on what he said. Basically he was telling to think more of others and that being in charge was not simply about being a good worker.

It was advice that eventually led to real change. I stopped gunning for promotions and focused on being a good co-worker. Once I did that, then eventually the promotions came and I was ready for the jobs I managed to earn.