how to stay motivated, when dealing with stressful situations

I'm good with exercise and diet but as soon as something tragic happens I lose track. How do I prevent this from happening?