python raise and exit code example
Example 1: python raise error exit
sys.exit('My error message')
print >>sys.stderr, "fatal error"
print("fatal error", file=sys.stderr)
raise SystemExit('error in code want to exit')
try:
raise SystemExit('error in code want to exit')
except:
print("program is still open")
Example 2: python raise and exit
def main():
try:
create_logdir()
create_dataset()
unittest.main()
except Exception as e:
logging.exception(e)
raise SystemExit
if __name__ == '__main__':
main()