python except as e code example
Example 1: except as Exception:
>>> def catch():
... try:
... asd()
... except Exception as e:
... print e.message, e.args
...
>>> catch()
global name 'asd' is not defined ("global name 'asd' is not defined",)
Example 2: python 3 except sys error info
1 import sys
2 try:
3 untrusted.execute()
4 except:
5 e = sys.exc_info()[0]
6 write_to_page( "<p>Error: %s</p>" % e )
Example 3: python except exception as e
try:
print('Test')
except (SyntaxError, IndexError) as E:
print('Synthax or index error !')
except :
print('Other error !')
else:
print('No error')
finally:
print('Done')
print('Anything else')