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

Detailed explanation of Exception handling in Python

高洛峰
Release: 2017-03-08 09:59:17
Original
1480 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template