1def main():
2 try:
3 create_logdir()
4 create_dataset()
5 unittest.main()
6 except Exception as e:
7 logging.exception(e)
8 raise SystemExit
9
10if __name__ == '__main__':
11 main()
12
1# There are 3 approaches, the first as lvc mentioned is using sys.exit
2sys.exit('My error message')
3
4# The second way is using print, print can write almost anything including an error message
5print >>sys.stderr, "fatal error" # Python 2.x
6print("fatal error", file=sys.stderr) # Python 3.x
7
8# The third way is to rise an exception which I don't like because it can be try-catch
9raise SystemExit('error in code want to exit')
10
11# it can be ignored like this
12try:
13 raise SystemExit('error in code want to exit')
14except:
15 print("program is still open")