Handle specific exception type in python -
i have code handles exception, , want specific if it's specific exception, , in debug mode. example:
try: stuff() except exception e: if _debug , e keyboardinterrupt: sys.exit() logging.exception("normal handling")
as such, don't want add a:
except keyboardinterrupt: sys.exit()
because i'm trying keep difference in debug code minimal
well, really, should keep handler keyboardinterrupt
separated. why want handle keyboard interrupts in debug mode, swallow them otherwise?
that said, can use isinstance
check type of object:
try: stuff() except exception e: if _debug , isinstance(e, keyboardinterrupt): sys.exit() logger.exception("normal handling")
Comments
Post a Comment