3 ms·
You really shouldn't let the program continue if it's in an error state which hasn't been recovered from and can't be recovered from. You should hard fail if yo
by lhnz 4y ago
You really shouldn't let the program continue if it's in an error state which hasn't been recovered from and can't be recovered from. You should hard fail if you're in such a state.
Otherwise, I would always throw and then only log errors in a single place within your application code. This avoids the need to be able to inject the correct type of logger into library code, etc. And makes it easier to attach other information about the execution of the application into the eventual error log line.
The important thing is that your errors are clearly understandable at the point that they are logged, therefore I also recommend creating your own granular application-level error types that wrap any underlying errors, writing sensible error messages, and attaching contextual state about the process that failed.