The best laid plans of mice and men gang aft agley. Or something like that. I hope Robert Burns isn't rolling in his grave. Our best efforts often go for naught. Which may be an explanation for why Edison said that genius was 99% perspiration: he had to try and fail so many times before his success.
Some problems are just not going to work out, and that's a matter of trial and error. You may, for example, work hard for days or weeks over a draft that just doesn't work out and may not even give you a lot of help as to what could be done better. That's purely hypothetical, of course; I wouldn't want to suggest that I had ever experienced anything of the sort today.
You try and try and try again. Your patience is tested. You get frustrated. Angry. A sense of failure wells up in your stomach, and the bile in your throat like you ate something rotten that's about to very seriously disagree with you. All this, and it's not your doing anyway. It's not like you're not smart and hard working and honest and diligent; it's just that the chips haven't fallen into place. It's possible they never will, and you'll have to move on to a new project or a completely new approach. Some efforts you just have to abandon and stop throwing good money after bad. Some projects will wreak havoc on your emotions unless you can maintain a good emotional distance from the project.
If the project falls through, it falls through. Sometimes we're gonna be frustrated and we'll just have to pick ourselves up off the ground and stick at it. In such situations it is beneficial to keep emotionally distant from the event: a setback is not an indicator of a person's worth. A setback is better viewed as an opportunity to learn more about how to reach your goal.