Properly handling things is about reverting all side effects to get to initial predictable state from where you can start over. Context doesn't help here. What helps is isolation or rather structuring your program around lightweight isolated processes. Where you can be sure that anything within process boundaries doesn't affect any other process and so you can just restart it if something blows up in it.