I want to define an exit code for some exceptions and some exceptions only. I want that the only input is that dictionary with the definition.
import sys
exit_codes = { ValueError:'10', KeyError:'25' }
try:
raise Some_Exception
except Exception as exit_err:
if any([isinstance(exit_err, exceptions) for exceptions in exit_codes.keys()]):
exit_code = int(exit_codes[type(exit_err)])
sys.exit(exit_code)
else:
raise exit_err
except Exception
is the only part that troubles me, however this seems approach seems safe.