Python exception logging

黄舟
Release: 2016-12-17 16:25:12
Original
1788 people have browsed it

1. Common exception names

AttributeError is an exception caused by calling a non-existent method.

EOFError Exception raised when the end of file is encountered.

ImportError Exception caused by an error in importing the module.

IndexError Exception caused by list out of bounds.

IOError Exceptions caused by I/O operations, such as errors in opening files, etc.

KeyError Exception raised by using a keyword that does not exist in the dictionary.

NameError Exception raised by using a non-existent variable name.

TabError Exception caused by incorrect statement block indentation.

ValueError Exception raised by searching for a value that does not exist in the list.

ZeroDivisionError Exception caused by dividing by zero.

2. Syntax

try:

...guarded clause...

except...exPRession... :

...exception handler codee...

finally:

. ..clean-up code...

3. raise statement

def crossProduct(seq1, seq2):

if not seq1 and not seq2:

raise ValueError, "Sequence arguments must be non-empty. "

return [(x, y) for x1 in seq1 for x2 in seq2]

The above is the content of Python exception records. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


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