How can I get exception type in python 1.5.2?
:
try:
raise "ABC"
except Exception as e:
print str(e)
gives a SyntaxError:
except Exception as e:
^
SyntaxError: invalid syntax
EDIT:
this does not work:
try:
a = 3
b = not_existent_variable
except Exception, e:
print "The error is: " + str(e) + "\n"
a = 3
b = not_existent_variable
as I only get the argument and not the actual error (NameError):
The error is: not_existent_variable
Traceback (innermost last):
File "C:\Users\jruegg\Desktop\test.py", line 8, in ?
b = not_existent_variable
NameError: not_existent_variable
source
share