Custom exit with only some exceptions in Python 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.
You can use a tuple of exception types with except, so your except clause could be simplified to:

except tuple(exit_codes) as exit_err:
    exit_code = int(exit_codes[type(exit_err)])
    sys.exit(exit_code)