I have the following code - I've commented next to the line where I don't understand the results.
class A:
pass;
class B(A):
pass;
class C(B):
pass;
for i in [A,B,C]:
try:
raise i();
except C:
print("C");
except B:
print("B");
### if i write A(), it shows: __main__.A: <__main__.A instance at 0x00ACBE18>
except A:
print("A");
This is my first time using the site, so please let me know if anything requires clarification...
Ais a class. when you write A() you actually instantiate the classAWhen you raise an instance of class
Aas an exception (wheni = A), there is noexceptclause that will catch this instance when it is written like thisA()So what that you see:
__main__.A: <__main__.A instance at 0x00ACBE18>is the instance that has been raise and no one catches it.You actually can use
()in. try it on C().Will output:
You can read more about errors and exceptions in python here.