"And David said in his heart, I shall now perish one day by the hand of Saul: there is nothing better for me than that I should speedily escape into the land of the Philistines; and Saul shall despair of me, to seek me any more in any coast of Israel: so shall I escape out of his hand." (1 Samuel 27: 1)
When we read the Old Testamen through the revelation of Christ and Him Crucified, we can see His glory even when the saints of the Old Testament saw nothing but doom.
David had already been anointed King of Israel, and he had gathered together four hundred mighty men. That number grew to six hundred (1 Samuel 27: 2), when David despaired and retired to Gath.
More interesting, however, David had faced off against Saul one last time, and just when he could have killed the rejected king, David only took Saul's spear and a pitcher of water as proof that he would not slay Saul, nor was he the threat which Saul had wickedly assumed. David even rebuked those who have killed Saul, not because of mere pity, but because David believed that God would take care of Saul for him (See 1 Samuel 26: 5-25).
After conversing with David, Saul called David "my son" and blessed him, then went his way. There is no record that Saul was going to change his mind, and they never fought or even saw each other again.
Yet still, David despaired.
What we can take from this passage is that even when we get discouraged, even when we feel bad, or scared, we must know and believe (it has nothing to do with feeling!) that God is on our side, that He loves us (1 John 4: 10) as His Beloved (Ephesians 1: 3; 1 John 4: 17).
Why is God on our side? Because of Jesus, who is seated at the right hand of the father, the mediator of the New Covenant (Hebrews 9: 15), in which we have been perfected forever before God (Hebrews 10: 14), standing in Jesus' own righteousness (2 Corinthians 5: 21)
Never despair because you have despaired, for we are saved by grace through faith, not anything on our part (Ephesians 2: 4-6). Even though David fled to the Philistines, even there he found grace before his own enemies (1 Samuel 27: 5), and even when the very Philistine who has favored him then turned him away (1 Samuel 29: 8-11), the rejection only set up David to step into the full reign for which God had already anointed him to receive.