Sometimes a breakup can feel like getting slapped in the face by a test you just bombed. You put a lot of time and effort into it, but for some reason, it didn't work out. If you are struggling in a course, let's say it is algebra, you are encouraged to keeping trying lots of new problems, and to work through them. Practice. Practice. Practice. And that is totally acceptable-encouraged even. So why should dating be any different?
At the beginning of a course, you aren't expected to know everything. You have to use your prior knowledge, apply what you know and incorporate new information as it's being fed into your brain. So if you feel like you aren't or weren't the best boyfriend or girlfriend maybe it's time to give yourself a break. Just like a school course, you can choose to give up or learn from your mistakes. I suggest the latter in both cases.
Everyone needs to realize that sometimes it's just not meant to be. Sure. He was a great guy. He remembered your favorite song and bought you flowers on Valentine's day. I bet she was beautiful, smart and could make you laugh too. But just because you have things in common doesn't mean that is the one you want (or should) spend the rest of your life with, and that's okay. Dating is the process of figuring out what you want in a future spouse, whether it be about religion, personality, career or the like. Like any process, there's a lot of (perfectly healthy) trial and error that goes on. Time should be your friend here, not your enemy.
In any case, a relationship is a two-way street, and as a very wise mentor of mine cautioned, "It only takes one person to ruin a relationship." This may seem harsh but its the reality. Some things are and will always be out of our control. As human beings, we all have our agency to choose and make decisions whether they are good or bad. As an unfortunate fact of life, we all get to deal with bad consequences as a result of other people's actions.
No one is guaranteed a perfect relationship or even a lasting one at that. There is always the possibility, no matter how small, that things might not work out. But, that being said, dwelling on the negative possible outcomes brings fear and mistrust which will only hinder relationships. Instead, it may be helpful to apply the principal as follows: practice makes potential. That is, the more you put yourself out there, meet new people, gain new relationship insights and the like, the more likely you will learn to develop lasting relationships. We can learn valuable lessons from all relationships whether they are good or bad.