1try:
2 print("I will try to print this line of code")
3except:
4 print("I will print this line of code if an error is encountered")
1def FileCheck(fn):
2 try:
3 open(fn, "r")
4 return 1
5 except IOError:
6 print "Error: File does not appear to exist."
7 return 0
8
9result = FileCheck("testfile")
10print result
1import sys
2def my_except_hook(exctype, value, traceback):
3 if exctype == KeyboardInterrupt:
4 print "Handler code goes here"
5 else:
6 sys.__excepthook__(exctype, value, traceback)
7sys.excepthook = my_except_hook