The SHORT ANSWER:
Sometimes, bad things happen to you. And in your opinion, they aren’t good. AT ALL. But your opinion is mortal, limited, finite. And ALLAH Knows Best (for He is immortal, unlimited, infinite).
الحمد لله والصلاة والسلام على رسول الله
All praise is due to ALLAH and peace and blessing upon His Messenger
بسم الله الرحمن الرحيم
In the Name of Allah, The Most Gracious, The Most Merciful
Indeed, you may believe that the boulder at the end could represent a catastrophe in this life that you were saved from (if you only knew) – or else, it could have been a more consequential favour: the boulder might have represented the final calamity of an eternity in hellfire in the Life Hereafter that you were saved from (if you only knew). And ALLAH Knows Best.
The conclusion is to be thankful to ALLAH in good times AND bad times, as demonstrated in the clip, above, with the words, “Alhamdulillah” (All Praise is for ALLAH).
Sometimes, you make a prayer and hope for something, but ALLAH doesn’t give it, and you may conclude (incorrectly) that He isn’t listening or He doesn’t care – and you interpret this as an ‘evil’ thing. There are three possible responses to your prayers – so long as you’re genuine:
The LONG ANSWER:
سبحان ربك رب العزة عما يصفون وسلام على المرسلين والحمد لله رب العالمين والصلاة والسلام على رسول الله محمد وعلى اله وصحبه أجمعين
Exalted be your Lord, the Lord of Glory, above what they attribute to Him, and peace be upon the Messengers, and all praise be to Allah, the Lord of the Universe. And the peace and blessing upon prophet Mohammed and his relatives and all his companions.