Home > Article > Backend Development > Detailed explanation of Exception handling in Python
About exception handling:
Class definitions in Python can be passed as objects. In the example, class B inherits the Exception class. In the loop, an exception class object B is raised each time. Except catches this exception and loops 3 times, so B B B is output.
Example:
class B(Exception): passclass C(B): passclass D(C): passfor cls in [B, C, D]: try: raise cls() except B: print ("B") except C: print("C") except D: print("D")
Execution result:
B
B
B
More details For articles related to Exception handling in Python, please pay attention to the PHP Chinese website!