python except errors code example
Example 1: python 3 except sys error info
1 import sys
2 try:
3 untrusted.execute()
4 except: # catch *all* exceptions
5 e = sys.exc_info()[0]
6 write_to_page( "<p>Error: %s</p>" % e )
Example 2: python try except print error
1 (x,y) = (5,0)
2 try:
3 z = x/y
4 except ZeroDivisionError as e:
5 z = e # representation: "<exceptions.ZeroDivisionError instance at 0x817426c>"
6 print z # output: "integer division or modulo by zero"