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:
Either use the standard method mentioned in the other answers, or if you really want to test within the except block then you can use isinstance().
try: stuff() except Exception as e: if _debug and isinstance(e, KeyboardInterrupt): sys.exit() logging.exception("Normal handling")