I looking for some "best-practice" advice.
In my Python app I am using exceptions for controlling the flow of my program. But I am not sure where I should log the exception. My gut feeling says I should log it closest to where the exception is raised. But that results in some rather clunky code:
def a_deeper_level_function():
print("I am doing stuff, but it goes wrong. So raising.")
# but I also want to log here with the same message.
# so I put my msg in a separate variable to re-use it.
msg = "this is the logging and exception message"
_LOGGER.error(msg)
raise Exception(msg)
Any thoughts appreciated!