As others have said go do something else if that can happen then switch domains and work on something you consider fun either because you like the domain or the challenge.
Trying to push through with coding doesn't work.
Another trick would be to step out of the editor and hit the white board while on your feet. Programming isn't typing and if you are trying to figure out a problem at the keyboard theres a good chance you already failed (unless your learning the language). Get it on paper/chalk/whiteboard and reason about it, talk about it with someone or a rubber duck.