No one likes rejection. Whether it's a romantic relationship or a business transaction, it's a similar sting to the heart. As a business, there are right ways and wrong ways to handle how you react when a client either rejects you or replaces you altogether. I can't help you on the romantic issue, sorry.
If you discover a project you were slated to work on was passed off to someone else, don't get upset. Well, don't call your client screaming and yelling about it. They won't respond to that very well and it might kill your professional relationship with them. Feeling bad from the discovery is perfectly normal, but don't be controlled by your emotions. Instead, walk away from your computer/phone, take a deep breath, have some coffee, grab a snack, do literarily anything other than press SEND on that email you drafted. Take as long as you need to come down from your rage. It could take hours or days, but give yourself a chance to soothe your emotions to a calm state. Once you've calmed down enough to be rational, move on to the next step.
If you emailed or called your client about that project but heard nothing back, contact them again. Clients get busy, just like the rest of us, and maybe they lost your email in an inbox that is swimming with notices and meeting requests. They could have forgotten to get back to you about an update on the project. The date moved, or the money fell through, or something outside of their power occurred and they simply forgot to inform you of it. The likelihood it was something personal is very low, as long as you have been professional with them. Never take rejection personally.
If you want to know more about what happened, be honest that you'd like to know if it was something you did. Was the project not going in the direction they wanted? Was it over budget? Were you not emailing them often enough? Were you emailing too often? Open the lines of communication and inform your client that you'd like them to be honest about what happened. Let them know that you'd like to avoid similar situations in the future, either with them or with other clients. This will make your client feel more in control and assure them that the truth won't hurt your feelings. It's a big reason why clients don't confront their designers. Rejection isn't easy for either party. Imagine how they might feel having to inform you that you've been replaced.
Throughout the entire process of discovery and inquiries, always be professional. If you see the end result of the project that was taken away, don't bad mouth it. Even if the quality is below what you would have produced, say nothing to your client about it. Again, the reasons for switching to another freelancer could have been outside of their control. They might not like the end results either but needed it done for one reason or another. Even if you never find out the real reasons why things fell through, don't forget to be professional.
The first few times you get rejected or replaced will hurt, but you'll get through it. It will happen again too, even with all the safety nets in place, it will happen again. The best practice is to learn how to deal with it like a pro and move on. Unless your client shuts the door of future opportunities, never shut one on them. They might come back later when the budget is bigger or someone else is in charge. Keeping an open door policy with past clients is better than shutting them out because your feelings got hurt. Don't take rejection personally.