def exit_with_exc_info(code=1, message='', print_tb=False, exception=None):
    exc_type, exc_value = (exception.__class__, exception) \
                          if exception is not None else sys.exc_info()[:2]

    if exc_type is not None:
        if print_tb:
            traceback.print_exc()
        elif isinstance(exc_value, KeyboardInterrupt):
            sys.stderr.write('^C\n')
        else:
            for line in traceback.format_exception_only(exc_type, exc_value):
                sys.stderr.write(line)

    sys.stderr.write(message)
    if message != '' and not message.endswith('\n'):
        sys.stderr.write('\n')
    sys.exit(code)
Exits the program, printing information about the last exception (if
dataset/ETHPy150Open dnanexus/dx-toolkit/src/python/dxpy/exceptions.py/exit_with_exc_info