exc = None
try:
raise Exception
except Exception as exc:
pass
print(exc)
NameError: name 'exc' not defined
This is used to work in Python2. Why has this changed so much? If I could at least reassign exc, similar to class level attributes
class Foo(object):
Bar = Bar
but this does not make it work:
exc = None
try:
raise Exception
except Exception as exc:
exc = exc
Any good tips to achieve the same? I would rather not write something like this:
exc = None
try:
raise Exception("foo")
except Exception as e:
exc = e
print(exc)
source
share