I have some code that handles an exception, and I want to do something specific only if it\'s a specific exception, and only in debug mode. So for example:
try:
You should let KeyboardInterrupt bubble all the way up and trap it at the highest level.
if __name__ == '__main__': try: main() except KeyboardInterrupt: sys.exit() except: pass def main(): try: stuff() except Exception as e: logging.exception("Normal handling") if _debug: raise e