Sometimes things go horribly wrong. This psalm seems to have been written when David's life was awful, but somehow David could laugh at those who insisted that God abandoned him. I suppose if you live in the wilderness long enough, with enough people trying to kill you, you can learn that none of the trials you face are as big a deal as God is. In the midst of trouble, fix your eyes of God.
Psalms 11:4 The LORD is in his holy temple; the LORD is on his heavenly throne. He observes everyone on earth; his eyes examine them.