Python error/exception handling

This code quickly shows how to do basic error handling in python

try:
  # None + 1
  raise ZeroDivisionError
except ZeroDivisionError:
  print 'You cannot divide by zero!'
except:
  print sys.exc_info()[0]
else:
 print 'No errors raised'
finally:
 print 'Run Clean up actions'

Leave a Reply