python print exception and pass code example
Example 1: try except python
try: #try to do the following
print("Hi there")
except: #If what is meant to happen in (try) fails, do this.
print("A error happened with the code above")
Example 2: python defualt error handler
import sys
def my_except_hook(exctype, value, traceback):
if exctype == KeyboardInterrupt:
print "Handler code goes here"
else:
sys.__excepthook__(exctype, value, traceback)
sys.excepthook = my_except_hook