When you write except NameError, you say that you want to catch exceptions of the type that is referenced NameErrorat the moment you execute the trap. Since you changed what NameErroryou are trying to catch your new class. But the exception created is “real,” NameErrornot your excessive one.
You can see this if you change the except clause:
try:
ccc
except Exception as e:
print isinstance(e, NameError)
print isinstance(e, OldNameError)
Conclusion:
False
True
., OldNameError, NameError.
, - undefined. , NameError, , ( ).