Dwelling on failure will actually help you improve, according to a study.