3 ms·
The real world is always going to be different to your development environment. You can't necessarily go into debug mode. Therefore logging is your friend. Nor
by Theodores 4y ago
The real world is always going to be different to your development environment. You can't necessarily go into debug mode. Therefore logging is your friend.
Normally I leverage the underlying logging and get my code to write to its own log file. I like it if I can independently turn on the logging and the verbosity for my module, even if logging is turned off for performance reasons in the main code.
Once everything actually works you might end up with 'carpet logging' in your code, where every bit of data is getting logged just in case there is an error. You might also have catch blocks around everything.
At this stage you can remove the excess logging and allow exceptions to bubble up, resisting the temptation to refactor anything else. If this works and you have something stable, then you can optimise your code without it being 'premature'.
I agree with @jameshush, however, if the code you are working with throws exceptions and has a sophisticated way of dealing with them, then you can throw exceptions that are going to work with what there is already.