Here is, 1. The great distress that David was in. He was in affliction, and ready to perish in his affliction, not likely to die, so much as likely to despair; he was ready to give up all for gone, and to look upon himself as cut off from God’s sight; he therefore admires the goodness of God to him, that he had not perished, that he kept the possession of his own soul, and was not driven out of his wits by his troubles, but especially that he was enabled to keep close to his God and was not driven off from his religion by them. Though we are not kept from affliction, yet, if we are kept from perishing in our affliction, we have no reason to say, We have cleansed our hands in vain; or, What profit is it that we have served God? 2. His support in this distress. God’s law was his delight, (1.) It had been so formerly, and the remembrance of that was a comfort to him, as it afforded him a good evidence of his integrity. (2.) It was so now in his affliction; it afforded him abundant matter of comfort, and from these fountains of life he drew living waters, when the cisterns of the creature were broken or dried up. His converse with God’s law, and his meditations on it, were his delightful entertainment in solitude and sorrow. A Bible is a pleasant companion at any time if we please.