Home  >  Article  >  Backend Development  >  Detailed explanation of Exception handling in Python

Detailed explanation of Exception handling in Python

高洛峰
高洛峰Original
2017-03-08 09:59:171443browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn