When to crash
The most severe log level is usually something like “critical” or “fatal”. This means execution cannot continue. When should you use this?
Often it’s an unrecoverable error, like running out of available memory. It gets tricky when it’s something like crucial data, like key configuration data. Can you fall back to defaults? Can the application still function in a meaningful way without it? What defines meaningful?
I find these two points helpful:
- Be consistent. Use the log levels/fatal crash functionality provided by your framework or language. Decide which situations call for crashing, document these guidelines and adhere to them.
- Be descriptive. Crashing or quitting with a message like “missing init file” is only partially helpful. Provide more details and context to help remedy the issue. It takes a little more effort when writing the message, but it pays off.