
Hello, I was going through the chapter as per the below link : https://docs.python.org/3/tutorial/errors.html#handling-exceptions The code shown is as below: class B(Exception): pass class C(B): pass class D(C): pass for cls in [B, C, D]: try: raise cls() except D: print("D") except C: print("C") except B: print("B") - Now as per the above code the statement written below confused me a little: *"A class in an except <https://docs.python.org/3/reference/compound_stmts.html#except> clause is compatible with an exception if it is the same class or a base class thereof (but not the other way around — an except clause listing a derived class is not compatible with a base class)."* - A class in the except clause is compatible with an exception if it is the same class: I agree to this. - However, the next part "or a base class thereof" confused me. Does this mean that if it is a base class (i.e a class which inherits from the exception class and is the base class of all the other classes C & D) only then will it be compatible? - Because if i reverse the order of the except clauses, the only prints would be 'B','B' and 'B'. I think this elaboration needs to be done. I would request you to provide your insights on this. Thanks and Regards, Rahul