The stage for this Psalm is David pondering the evil that surrounds him. "I saw the prosperity of the wicked...and their body is fat. They are not in trouble as other men...pride is their necklace...water of abundance are drunk by them...they say "how does God know?...behold these are the wicked...surely in vain I have kept my heart pure."
As David looks around he wonders why the wicked are able to prosper. His mind even goes as far as questioning if his "pure" way of living was in vain.
"If I had said, "I will speak thus,"behold, I would have betrayed a generation of Your children." David is saying, if I would have spoken according to my feelings I would have betrayed (or deceived) God's children. How often we as parents can do the same to our children because we speak in accordance to how we feel. "A fool vents all his feelings, but a wise man holds them back." Prov. 29:11
"When I pondered to understand this, it was troublesome in my sight." When we try to figure something out apart from the Lord it will always become "troublesome."
So, David did what we all need to do. "I came into the sanctuary of God; then I perceived." David remembered that all answers are found in God.
David realized that without the knowledge of God, the world around him caused his heart to be "embittered, pierced within and senseless."
We must always keep before us that, "all scripture is given by inspiration of God, and is profitable for doctrine, for reproof, for correction, for instruction in righteousness, that the man of God may complete, thoroughly equipped for every good work" 2 Tim. 3:16
The Psalm, or praises that David goes on to speak are full of hope and encouragement. "Nevertheless I am continually with you, You have taken a hold of my right hand; with Your counsel You will guide me...My flesh and my heart may fail but God is the strength of my heart and my portion forever...The nearness of Gos is my good. I have made the Lord God my refuge, THAT I MAY TELL OF ALL YOUR WORKS."
"Your testimonies are my delight and my counselors." Psalm 119:24