This song was composed for any who might be in deep distress, who might fear for their very lives, and who might know their own sins well enough to suspect that it's on account of them that they're experiencing trouble.
David had times like that. There were times when He knew he had sinned. At such times He was very, very ashamed of his sin, and he suspected that all who knew him were ashamed of him as well, and in fact that they were avoiding him like the plague. Not only so, but it always seemed to be just at that moment that his enemies were attacking him as well! They were cunning, powerful enemies, enemies who could, and gladly would, take away his life. He feared that his sin was the reason for all this and that perhaps the Lord had forsaken him.
But there was one thing he was determined to do: he was determined to maintain his trust in the Lord, even though the Lord might utterly desert him to his enemies. He had called on the Lord, and he was determined to wait on the Lord, come what may. He could say with Job, "Though He slay me, yet will I trust Him." He knew his only help had to come from God, so he stubbornly hung on - and kept praying.
Many might give up under such circumstances. This song was composed for them, composed to move them to "hang in there," no matter how desperate the circumstances.
And David knew they could be desperate. He had to confess, "My eye wastes away with grief, yes my soul and my body! For my life is spent with grief, and my years with sighing (his distress was not of short duration!); my strength fails because of my iniquity, and my bones waste away . . . I am forgotten like a dead man, out of mind; I am like a broken vessel. For I hear the slander of many; fear is on every side; while they take counsel together against me, they scheme to take away my life!"
But the answer, no matter how deep the distress, no matter how desperate the circumstances, no matter how long it had been - was still the Lord's grace. David sings, "My times are in Your hand; deliver me from the hand of my enemies, and from those who persecute me." NO MATTER WHAT, he was going to trust the Lord! He knew his sin, he'd confessed his sin, and he knew he was dealing with a forgiving God - and He was going to trust him!
Then, turning to the congregation, and having brought each worshipper this far in song, David makes it clear that God WAS merciful, God DID hear him, and God HAD delivered him! It's as though he were directly communicating with each one who sang this song, and he wanted them to know that, though trouble couldn't get any deeper and circumstances any more desperate, yet he's been delivered, and they could be too!
He sings, "Oh, how great is Your goodness, which You have laid up for those who fear You, which You have prepared for those who trust in You in the presence of the sons of men!" In summary of that goodness, he sings, "For I said in my haste, I am cut off from before Your eyes; nevertheless You heard the voice of my supplications when I cried out to you!"
David communicates the result of such stubborn prayer to each worshipper when he sings, "Oh love the Lord, all you His saints! For the Lord preserves the faithful, and fully repays the proud person. Be of good courage, and He shall strengthen your heart, all you who hope in the Lord!"
It's just as true for you as it was for David and the people he led. Have you trusted the Lord? Have you laid your sins before Him and known the forgiveness that is in Jesus Christ? Then HANG ON! David's trouble, David's sin, David's distress - was greater than any you'll ever experience - and God finally delivered him! And David's greater Son, our Lord Jesus Christ, experienced greater guilt, greater distress, greater desperation than you - or David - could ever experience, and He rose from the dead in triumph! And so will you!