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)!