Failure is a great time for reflection. When you fail you can use that as a chance to look at your goals and your strategy for achieving those objectives. Your goals do not necessarily need to change, but perhaps your approach should be revised to better position you for success in the long run.
Sometimes the most innovative and creative inventions and products are actually created by accident. You try to achieve one thing, you fail in some respects, but the product of your efforts is something different and wonderful in its own way. Be open-minded about what you do, and be open to failure; you never know what you might find.