When should one let an application crash because of an exception in Java (design issue)?
- by JVerstry
In most cases, it is possible to catch exceptions in Java, even unchecked ones. But, it is not necessarily possible to do something about it (for example out of memory).
For other cases, the issue I am trying to solve is a design principle one. I am trying to set-up a design principle or a set of rules indicating when one should give up on an exceptional situation, even if it is detected in time. The objective is trying to not crash the application as much as possible.
Has someone already brainstormed and communicated about this? I am looking for specific generic cases and possible solutions, or thumb-rules.
UPDATE
Suggestions so far:
Stop running if data coherency can be compromised
Stop running if data can be deleted
Stop running if you can't do anything about it (Out of memory...)
Stop running if key service is not available or becomes unavailable and cannot be restarted
If application must be stopped, degrade as gracefully as possible
Use rollbacks in db transactions
Log as much relevant information as you can
Notify the developers