Four years ago, my Dad died unexpectedly. That kicked off a challening few years for my family and I. Both our sons were born; my Mum died; we moved interstate a couple of times; bought and sold a few houses; my wife and I both changed jobs; we had some friends diagnosed with termial illnesses and others commit suicide. It's been pretty full on.
In general I'm good at handling stress and change but this has stretched me, at times to breaking. It feels like my resilience been gradually worn down to where anything unexpected can bring me crashing down.
Failing gracefully is about knowing that unexpected things will happen, and having measures in place to deal with them. In software dev, that means (amoungst other things) proper exception handling.
Taking my queue from that, I tried indentifying situations that I was handling poorly. It worked fairly well: I'd notice things going down a certain path and stop it before it got ugly.
As much as this was progress, it was the life equivelant of dumping the exception stack trace to a log. Sure, I may have stopped the spectacularly messy crash, but I hadn't done anything to deal with the underlying cause.
Lately I've started meditating. It is, in essence, debugging my brain: removing some of the chaos and disorganisation. For me it's not spiritual or religious: it's purely pragmatic. And, just like with code, investing a bit of time to clean out the cruft is helping things to run much more smoothly.