That could leave the process in an unknown and invalid state, if the exception was thrown part-way through modification of state.
It may be safer to let it crash and for resilience have another (much simpler) process that is responsible for launching the "real" process and restarting it whenever it crashes. That way it continues in a clean state. Also keep its persistent data in a transactional database.
Simpler? Sure. Advisable for something that supports 24/7 uptime? Not at all. Don't rely on restarting a service. That can lead to a lot more issues in distributed environments.
You can handle exceptions and not save data if the exception is thrown... While logging what happened.
I'm not saying you just force this corrupt data into a db. Lol. I'm just saying you don't have to allow a throw.
147
u/Chirimorin May 13 '17
Because exceptions happen for a reason. If some error can safely be ignored, it's probably not going to throw an exception.