The prophet(peace and blessing be upon him)forbade losing ones hope as it dispraised both legally and logically.He(peace and blessing be upon him)also guided the muslim,that when he is afflicted with some difficulty,not to say:if i had not done that,so and so would not have happened,but say,allah did what he ordained to do.(book of tawheed)