My way how to escape them is very simple.
I ignore them to be honest.
As Ned Vizzini wrote in "It’s Kind Of A Funny Story":
I didn’t want to wake up.
I was having a much better time asleep.
And that’s really sad.
It was almost like a reverse nightmare, like when you wake up from a nightmare you’re so relieved.
I woke up into a nightmare.
This "Nightmare" you woked up in is not undefined.
The Question you should ask yourself is:
"Why is this dream a nightmare?"
List yourself your problems and try to solve them.
If this dont works and/or you can't solve them on your own,try to search a psychologist.
Many people I knew that had depression or just thought they do,were helping them self with that method.