... except AttributeError:
... print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0])
... try: raise KeyError
-... except: print(sys.exc_info()[0] is KeyError or sys.exc_info()[0])
+... except:
+... print(sys.exc_info()[0] is KeyError or sys.exc_info()[0])
+... if IS_PY3:
+... print(isinstance(sys.exc_info()[1].__context__, AttributeError)
+... or sys.exc_info()[1].__context__)
+... else:
+... print(True)
... print((IS_PY3 and sys.exc_info()[0] is AttributeError) or
... (not IS_PY3 and sys.exc_info()[0] is KeyError) or
... sys.exc_info()[0])
True
True
True
+True
>>> print(sys.exc_info()[0]) # test_py()
None
True
True
True
+True
>>> print(sys.exc_info()[0]) # test_c()
None
True
True
True
+True
>>> print(sys.exc_info()[0]) # test_py2()
None
True
True
True
+True
>>> print(sys.exc_info()[0]) # test_c2()
None
"""
except AttributeError:
print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0])
try: raise KeyError
- except: print(sys.exc_info()[0] is KeyError or sys.exc_info()[0])
+ except:
+ print(sys.exc_info()[0] is KeyError or sys.exc_info()[0])
+ if IS_PY3:
+ print(isinstance(sys.exc_info()[1].__context__, AttributeError)
+ or sys.exc_info()[1].__context__)
+ else:
+ print(True)
print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0])
print(sys.exc_info()[0] is outer_exc or sys.exc_info()[0])