/
usr
/
share
/
doc
/
python3-docs
/
html
/
_sources
/
library
/
/usr/share/doc/python3-docs/html/_sources/library
mkdir
upload
Name
Size
Mode
Actions
2to3.rst.txt
15898
0644
edit
dl
rm
abc.rst.txt
11805
0644
edit
dl
rm
aifc.rst.txt
7503
0644
edit
dl
rm
allos.rst.txt
678
0644
edit
dl
rm
archiving.rst.txt
440
0644
edit
dl
rm
argparse.rst.txt
77480
0644
edit
dl
rm
array.rst.txt
10812
0644
edit
dl
rm
ast.rst.txt
10159
0644
edit
dl
rm
asynchat.rst.txt
8528
0644
edit
dl
rm
asyncio-dev.rst.txt
13398
0644
edit
dl
rm
asyncio-eventloop.rst.txt
33701
0644
edit
dl
rm
asyncio-eventloops.rst.txt
7660
0644
edit
dl
rm
asyncio-protocol.rst.txt
25170
0644
edit
dl
rm
asyncio-queue.rst.txt
4328
0644
edit
dl
rm
asyncio-stream.rst.txt
14363
0644
edit
dl
rm
asyncio-subprocess.rst.txt
15544
0644
edit
dl
rm
asyncio-sync.rst.txt
9078
0644
edit
dl
rm
asyncio-task.rst.txt
25406
0644
edit
dl
rm
asyncio.rst.txt
2272
0644
edit
dl
rm
asyncore.rst.txt
13624
0644
edit
dl
rm
atexit.rst.txt
3669
0644
edit
dl
rm
audioop.rst.txt
10712
0644
edit
dl
rm
base64.rst.txt
10371
0644
edit
dl
rm
bdb.rst.txt
12985
0644
edit
dl
rm
binary.rst.txt
654
0644
edit
dl
rm
binascii.rst.txt
6539
0644
edit
dl
rm
binhex.rst.txt
1709
0644
edit
dl
rm
bisect.rst.txt
5398
0644
edit
dl
rm
builtins.rst.txt
1465
0644
edit
dl
rm
bz2.rst.txt
8825
0644
edit
dl
rm
calendar.rst.txt
10988
0644
edit
dl
rm
cgi.rst.txt
22650
0644
edit
dl
rm
cgitb.rst.txt
2918
0644
edit
dl
rm
chunk.rst.txt
5094
0644
edit
dl
rm
cmath.rst.txt
9326
0644
edit
dl
rm
cmd.rst.txt
13795
0644
edit
dl
rm
code.rst.txt
7817
0644
edit
dl
rm
codecs.rst.txt
75564
0644
edit
dl
rm
codeop.rst.txt
3021
0644
edit
dl
rm
collections.abc.rst.txt
12861
0644
edit
dl
rm
collections.rst.txt
46063
0644
edit
dl
rm
colorsys.rst.txt
1820
0644
edit
dl
rm
compileall.rst.txt
8975
0644
edit
dl
rm
concurrency.rst.txt
673
0644
edit
dl
rm
concurrent.futures.rst.txt
16910
0644
edit
dl
rm
concurrent.rst.txt
171
0644
edit
dl
rm
configparser.rst.txt
48756
0644
edit
dl
rm
constants.rst.txt
3331
0644
edit
dl
rm
contextlib.rst.txt
28175
0644
edit
dl
rm
copy.rst.txt
3378
0644
edit
dl
rm
copyreg.rst.txt
2182
0644
edit
dl
rm
crypt.rst.txt
5122
0644
edit
dl
rm
crypto.rst.txt
411
0644
edit
dl
rm
csv.rst.txt
19902
0644
edit
dl
rm
ctypes.rst.txt
88613
0644
edit
dl
rm
curses.ascii.rst.txt
8920
0644
edit
dl
rm
curses.panel.rst.txt
2764
0644
edit
dl
rm
curses.rst.txt
76397
0644
edit
dl
rm
custominterp.rst.txt
569
0644
edit
dl
rm
datatypes.rst.txt
751
0644
edit
dl
rm
datetime.rst.txt
90524
0644
edit
dl
rm
dbm.rst.txt
14293
0644
edit
dl
rm
debug.rst.txt
471
0644
edit
dl
rm
decimal.rst.txt
74869
0644
edit
dl
rm
development.rst.txt
704
0644
edit
dl
rm
difflib.rst.txt
29861
0644
edit
dl
rm
dis.rst.txt
32567
0644
edit
dl
rm
distribution.rst.txt
452
0644
edit
dl
rm
distutils.rst.txt
1974
0644
edit
dl
rm
doctest.rst.txt
71743
0644
edit
dl
rm
dummy_threading.rst.txt
784
0644
edit
dl
rm
email.charset.rst.txt
9293
0644
edit
dl
rm
email.compat32-message.rst.txt
33493
0644
edit
dl
rm
email.contentmanager.rst.txt
9112
0644
edit
dl
rm
email.encoders.rst.txt
2715
0644
edit
dl
rm
email.errors.rst.txt
4792
0644
edit
dl
rm
email.examples.rst.txt
1915
0644
edit
dl
rm
email.generator.rst.txt
13637
0644
edit
dl
rm
email.header.rst.txt
9188
0644
edit
dl
rm
email.headerregistry.rst.txt
17957
0644
edit
dl
rm
email.iterators.rst.txt
2795
0644
edit
dl
rm
email.message.rst.txt
33008
0644
edit
dl
rm
email.mime.rst.txt
11721
0644
edit
dl
rm
email.parser.rst.txt
14092
0644
edit
dl
rm
email.policy.rst.txt
27022
0644
edit
dl
rm
email.rst.txt
6785
0644
edit
dl
rm
email.util.rst.txt
9214
0644
edit
dl
rm
ensurepip.rst.txt
4987
0644
edit
dl
rm
enum.rst.txt
32751
0644
edit
dl
rm
errno.rst.txt
6811
0644
edit
dl
rm
exceptions.rst.txt
25570
0644
edit
dl
rm
faulthandler.rst.txt
6136
0644
edit
dl
rm
fcntl.rst.txt
7152
0644
edit
dl
rm
filecmp.rst.txt
5623
0644
edit
dl
rm
fileformats.rst.txt
287
0644
edit
dl
rm
fileinput.rst.txt
8051
0644
edit
dl
rm
filesys.rst.txt
961
0644
edit
dl
rm
fnmatch.rst.txt
3103
0644
edit
dl
rm
formatter.rst.txt
13242
0644
edit
dl
rm
fpectl.rst.txt
4180
0644
edit
dl
rm
fractions.rst.txt
6364
0644
edit
dl
rm
frameworks.rst.txt
391
0644
edit
dl
rm
ftplib.rst.txt
17552
0644
edit
dl
rm
functional.rst.txt
365
0644
edit
dl
rm
functions.rst.txt
71621
0644
edit
dl
rm
functools.rst.txt
18503
0644
edit
dl
rm
gc.rst.txt
9694
0644
edit
dl
rm
getopt.rst.txt
6557
0644
edit
dl
rm
getpass.rst.txt
1882
0644
edit
dl
rm
gettext.rst.txt
25588
0644
edit
dl
rm
glob.rst.txt
3508
0644
edit
dl
rm
grp.rst.txt
2417
0644
edit
dl
rm
gzip.rst.txt
8301
0644
edit
dl
rm
hashlib.rst.txt
26523
0644
edit
dl
rm
heapq.rst.txt
13402
0644
edit
dl
rm
hmac.rst.txt
4020
0644
edit
dl
rm
html.entities.rst.txt
1319
0644
edit
dl
rm
html.parser.rst.txt
11275
0644
edit
dl
rm
html.rst.txt
1304
0644
edit
dl
rm
http.client.rst.txt
18870
0644
edit
dl
rm
http.cookiejar.rst.txt
27832
0644
edit
dl
rm
http.cookies.rst.txt
8645
0644
edit
dl
rm
http.rst.txt
7096
0644
edit
dl
rm
http.server.rst.txt
17639
0644
edit
dl
rm
i18n.rst.txt
408
0644
edit
dl
rm
idle.rst.txt
25834
0644
edit
dl
rm
imaplib.rst.txt
20367
0644
edit
dl
rm
imghdr.rst.txt
2938
0644
edit
dl
rm
imp.rst.txt
15548
0644
edit
dl
rm
importlib.rst.txt
53563
0644
edit
dl
rm
index.rst.txt
2258
0644
edit
dl
rm
inspect.rst.txt
53928
0644
edit
dl
rm
internet.rst.txt
992
0644
edit
dl
rm
intro.rst.txt
2645
0644
edit
dl
rm
io.rst.txt
40328
0644
edit
dl
rm
ipaddress.rst.txt
32340
0644
edit
dl
rm
ipc.rst.txt
649
0644
edit
dl
rm
itertools.rst.txt
38459
0644
edit
dl
rm
json.rst.txt
27876
0644
edit
dl
rm
keyword.rst.txt
617
0644
edit
dl
rm
language.rst.txt
522
0644
edit
dl
rm
linecache.rst.txt
2408
0644
edit
dl
rm
locale.rst.txt
25470
0644
edit
dl
rm
logging.config.rst.txt
33886
0644
edit
dl
rm
logging.handlers.rst.txt
42497
0644
edit
dl
rm
logging.rst.txt
60479
0644
edit
dl
rm
lzma.rst.txt
17361
0644
edit
dl
rm
macpath.rst.txt
707
0644
edit
dl
rm
mailbox.rst.txt
63055
0644
edit
dl
rm
mailcap.rst.txt
3691
0644
edit
dl
rm
markup.rst.txt
679
0644
edit
dl
rm
marshal.rst.txt
4855
0644
edit
dl
rm
math.rst.txt
14375
0644
edit
dl
rm
mimetypes.rst.txt
9839
0644
edit
dl
rm
misc.rst.txt
247
0644
edit
dl
rm
mm.rst.txt
431
0644
edit
dl
rm
mmap.rst.txt
11232
0644
edit
dl
rm
modulefinder.rst.txt
3240
0644
edit
dl
rm
modules.rst.txt
355
0644
edit
dl
rm
msilib.rst.txt
18612
0644
edit
dl
rm
msvcrt.rst.txt
4392
0644
edit
dl
rm
multiprocessing.rst.txt
104494
0644
edit
dl
rm
netdata.rst.txt
339
0644
edit
dl
rm
netrc.rst.txt
3007
0644
edit
dl
rm
nis.rst.txt
1993
0644
edit
dl
rm
nntplib.rst.txt
21821
0644
edit
dl
rm
numbers.rst.txt
8089
0644
edit
dl
rm
numeric.rst.txt
696
0644
edit
dl
rm
operator.rst.txt
18989
0644
edit
dl
rm
optparse.rst.txt
76996
0644
edit
dl
rm
os.path.rst.txt
16419
0644
edit
dl
rm
os.rst.txt
137534
0644
edit
dl
rm
ossaudiodev.rst.txt
17845
0644
edit
dl
rm
othergui.rst.txt
2822
0644
edit
dl
rm
parser.rst.txt
15148
0644
edit
dl
rm
pathlib.rst.txt
30045
0644
edit
dl
rm
pdb.rst.txt
19454
0644
edit
dl
rm
persistence.rst.txt
591
0644
edit
dl
rm
pickle.rst.txt
37440
0644
edit
dl
rm
pickletools.rst.txt
3729
0644
edit
dl
rm
pipes.rst.txt
2557
0644
edit
dl
rm
pkgutil.rst.txt
8730
0644
edit
dl
rm
platform.rst.txt
9624
0644
edit
dl
rm
plistlib.rst.txt
7398
0644
edit
dl
rm
poplib.rst.txt
8197
0644
edit
dl
rm
posix.rst.txt
3694
0644
edit
dl
rm
pprint.rst.txt
14274
0644
edit
dl
rm
profile.rst.txt
27969
0644
edit
dl
rm
pty.rst.txt
3123
0644
edit
dl
rm
pwd.rst.txt
2739
0644
edit
dl
rm
pyclbr.rst.txt
3297
0644
edit
dl
rm
pydoc.rst.txt
4688
0644
edit
dl
rm
pyexpat.rst.txt
28620
0644
edit
dl
rm
python.rst.txt
475
0644
edit
dl
rm
py_compile.rst.txt
3851
0644
edit
dl
rm
queue.rst.txt
7268
0644
edit
dl
rm
quopri.rst.txt
2571
0644
edit
dl
rm
random.rst.txt
18503
0644
edit
dl
rm
re.rst.txt
64936
0644
edit
dl
rm
readline.rst.txt
11943
0644
edit
dl
rm
reprlib.rst.txt
5162
0644
edit
dl
rm
resource.rst.txt
12291
0644
edit
dl
rm
rlcompleter.rst.txt
2294
0644
edit
dl
rm
runpy.rst.txt
8285
0644
edit
dl
rm
sched.rst.txt
4842
0644
edit
dl
rm
secrets.rst.txt
5930
0644
edit
dl
rm
select.rst.txt
28175
0644
edit
dl
rm
selectors.rst.txt
8925
0644
edit
dl
rm
shelve.rst.txt
8390
0644
edit
dl
rm
shlex.rst.txt
16441
0644
edit
dl
rm
shutil.rst.txt
26014
0644
edit
dl
rm
signal.rst.txt
17218
0644
edit
dl
rm
site.rst.txt
9628
0644
edit
dl
rm
smtpd.rst.txt
10806
0644
edit
dl
rm
smtplib.rst.txt
23439
0644
edit
dl
rm
sndhdr.rst.txt
1994
0644
edit
dl
rm
socket.rst.txt
68202
0644
edit
dl
rm
socketserver.rst.txt
23712
0644
edit
dl
rm
spwd.rst.txt
2958
0644
edit
dl
rm
sqlite3.rst.txt
39215
0644
edit
dl
rm
ssl.rst.txt
96021
0644
edit
dl
rm
stat.rst.txt
9805
0644
edit
dl
rm
statistics.rst.txt
15301
0644
edit
dl
rm
stdtypes.rst.txt
179240
0644
edit
dl
rm
string.rst.txt
35374
0644
edit
dl
rm
stringprep.rst.txt
4279
0644
edit
dl
rm
struct.rst.txt
19581
0644
edit
dl
rm
subprocess.rst.txt
45793
0644
edit
dl
rm
sunau.rst.txt
7390
0644
edit
dl
rm
superseded.rst.txt
258
0644
edit
dl
rm
symbol.rst.txt
975
0644
edit
dl
rm
symtable.rst.txt
4964
0644
edit
dl
rm
sys.rst.txt
58273
0644
edit
dl
rm
sysconfig.rst.txt
8749
0644
edit
dl
rm
syslog.rst.txt
4302
0644
edit
dl
rm
tabnanny.rst.txt
2007
0644
edit
dl
rm
tarfile.rst.txt
31749
0644
edit
dl
rm
telnetlib.rst.txt
7899
0644
edit
dl
rm
tempfile.rst.txt
13857
0644
edit
dl
rm
termios.rst.txt
3751
0644
edit
dl
rm
test.rst.txt
25764
0644
edit
dl
rm
text.rst.txt
584
0644
edit
dl
rm
textwrap.rst.txt
10519
0644
edit
dl
rm
threading.rst.txt
39257
0644
edit
dl
rm
time.rst.txt
32967
0644
edit
dl
rm
timeit.rst.txt
13000
0644
edit
dl
rm
tk.rst.txt
1639
0644
edit
dl
rm
tkinter.rst.txt
33027
0644
edit
dl
rm
tkinter.scrolledtext.rst.txt
1255
0644
edit
dl
rm
tkinter.tix.rst.txt
22653
0644
edit
dl
rm
tkinter.ttk.rst.txt
58489
0644
edit
dl
rm
token.rst.txt
2607
0644
edit
dl
rm
tokenize.rst.txt
10002
0644
edit
dl
rm
trace.rst.txt
6914
0644
edit
dl
rm
traceback.rst.txt
17854
0644
edit
dl
rm
tracemalloc.rst.txt
22089
0644
edit
dl
rm
tty.rst.txt
1097
0644
edit
dl
rm
turtle.rst.txt
71221
0644
edit
dl
rm
types.rst.txt
9999
0644
edit
dl
rm
typing.rst.txt
34332
0644
edit
dl
rm
undoc.rst.txt
780
0644
edit
dl
rm
unicodedata.rst.txt
5762
0644
edit
dl
rm
unittest.mock-examples.rst.txt
46206
0644
edit
dl
rm
unittest.mock.rst.txt
85991
0644
edit
dl
rm
unittest.rst.txt
93304
0644
edit
dl
rm
unix.rst.txt
446
0644
edit
dl
rm
urllib.error.rst.txt
2199
0644
edit
dl
rm
urllib.parse.rst.txt
27332
0644
edit
dl
rm
urllib.request.rst.txt
59360
0644
edit
dl
rm
urllib.robotparser.rst.txt
2969
0644
edit
dl
rm
urllib.rst.txt
466
0644
edit
dl
rm
uu.rst.txt
2387
0644
edit
dl
rm
uuid.rst.txt
8760
0644
edit
dl
rm
venv.rst.txt
20621
0644
edit
dl
rm
warnings.rst.txt
20152
0644
edit
dl
rm
wave.rst.txt
6870
0644
edit
dl
rm
weakref.rst.txt
21328
0644
edit
dl
rm
webbrowser.rst.txt
9783
0644
edit
dl
rm
windows.rst.txt
272
0644
edit
dl
rm
winreg.rst.txt
24073
0644
edit
dl
rm
winsound.rst.txt
5134
0644
edit
dl
rm
wsgiref.rst.txt
33047
0644
edit
dl
rm
xdrlib.rst.txt
8078
0644
edit
dl
rm
xml.dom.minidom.rst.txt
10198
0644
edit
dl
rm
xml.dom.pulldom.rst.txt
5186
0644
edit
dl
rm
xml.dom.rst.txt
39507
0644
edit
dl
rm
xml.etree.elementtree.rst.txt
43871
0644
edit
dl
rm
xml.rst.txt
6071
0644
edit
dl
rm
xml.sax.handler.rst.txt
15399
0644
edit
dl
rm
xml.sax.reader.rst.txt
12133
0644
edit
dl
rm
xml.sax.rst.txt
7159
0644
edit
dl
rm
xml.sax.utils.rst.txt
3901
0644
edit
dl
rm
xmlrpc.client.rst.txt
23071
0644
edit
dl
rm
xmlrpc.rst.txt
475
0644
edit
dl
rm
xmlrpc.server.rst.txt
14990
0644
edit
dl
rm
zipapp.rst.txt
17392
0644
edit
dl
rm
zipfile.rst.txt
24005
0644
edit
dl
rm
zipimport.rst.txt
5805
0644
edit
dl
rm
zlib.rst.txt
13912
0644
edit
dl
rm
_dummy_thread.rst.txt
762
0644
edit
dl
rm
_thread.rst.txt
6886
0644
edit
dl
rm
__future__.rst.txt
5245
0644
edit
dl
rm
__main__.rst.txt
904
0644
edit
dl
rm
Edit:
/usr/share/doc/python3-docs/html/_sources/library/exceptions.rst.txt
(25570B)
.. _bltin-exceptions: Built-in Exceptions =================== .. index:: statement: try statement: except In Python, all exceptions must be instances of a class that derives from :class:`BaseException`. In a :keyword:`try` statement with an :keyword:`except` clause that mentions a particular class, that clause also handles any exception classes derived from that class (but not exception classes from which *it* is derived). Two exception classes that are not related via subclassing are never equivalent, even if they have the same name. .. index:: statement: raise The built-in exceptions listed below can be generated by the interpreter or built-in functions. Except where mentioned, they have an "associated value" indicating the detailed cause of the error. This may be a string or a tuple of several items of information (e.g., an error code and a string explaining the code). The associated value is usually passed as arguments to the exception class's constructor. User code can raise built-in exceptions. This can be used to test an exception handler or to report an error condition "just like" the situation in which the interpreter raises the same exception; but beware that there is nothing to prevent user code from raising an inappropriate error. The built-in exception classes can be subclassed to define new exceptions; programmers are encouraged to derive new exceptions from the :exc:`Exception` class or one of its subclasses, and not from :exc:`BaseException`. More information on defining exceptions is available in the Python Tutorial under :ref:`tut-userexceptions`. When raising (or re-raising) an exception in an :keyword:`except` or :keyword:`finally` clause :attr:`__context__` is automatically set to the last exception caught; if the new exception is not handled the traceback that is eventually displayed will include the originating exception(s) and the final exception. When raising a new exception (rather than using a bare ``raise`` to re-raise the exception currently being handled), the implicit exception context can be supplemented with an explicit cause by using :keyword:`from` with :keyword:`raise`:: raise new_exc from original_exc The expression following :keyword:`from` must be an exception or ``None``. It will be set as :attr:`__cause__` on the raised exception. Setting :attr:`__cause__` also implicitly sets the :attr:`__suppress_context__` attribute to ``True``, so that using ``raise new_exc from None`` effectively replaces the old exception with the new one for display purposes (e.g. converting :exc:`KeyError` to :exc:`AttributeError`, while leaving the old exception available in :attr:`__context__` for introspection when debugging. The default traceback display code shows these chained exceptions in addition to the traceback for the exception itself. An explicitly chained exception in :attr:`__cause__` is always shown when present. An implicitly chained exception in :attr:`__context__` is shown only if :attr:`__cause__` is :const:`None` and :attr:`__suppress_context__` is false. In either case, the exception itself is always shown after any chained exceptions so that the final line of the traceback always shows the last exception that was raised. Base classes ------------ The following exceptions are used mostly as base classes for other exceptions. .. exception:: BaseException The base class for all built-in exceptions. It is not meant to be directly inherited by user-defined classes (for that, use :exc:`Exception`). If :func:`str` is called on an instance of this class, the representation of the argument(s) to the instance are returned, or the empty string when there were no arguments. .. attribute:: args The tuple of arguments given to the exception constructor. Some built-in exceptions (like :exc:`OSError`) expect a certain number of arguments and assign a special meaning to the elements of this tuple, while others are usually called only with a single string giving an error message. .. method:: with_traceback(tb) This method sets *tb* as the new traceback for the exception and returns the exception object. It is usually used in exception handling code like this:: try: ... except SomeException: tb = sys.exc_info()[2] raise OtherException(...).with_traceback(tb) .. exception:: Exception All built-in, non-system-exiting exceptions are derived from this class. All user-defined exceptions should also be derived from this class. .. exception:: ArithmeticError The base class for those built-in exceptions that are raised for various arithmetic errors: :exc:`OverflowError`, :exc:`ZeroDivisionError`, :exc:`FloatingPointError`. .. exception:: BufferError Raised when a :ref:`buffer <bufferobjects>` related operation cannot be performed. .. exception:: LookupError The base class for the exceptions that are raised when a key or index used on a mapping or sequence is invalid: :exc:`IndexError`, :exc:`KeyError`. This can be raised directly by :func:`codecs.lookup`. Concrete exceptions ------------------- The following exceptions are the exceptions that are usually raised. .. exception:: AssertionError .. index:: statement: assert Raised when an :keyword:`assert` statement fails. .. exception:: AttributeError Raised when an attribute reference (see :ref:`attribute-references`) or assignment fails. (When an object does not support attribute references or attribute assignments at all, :exc:`TypeError` is raised.) .. exception:: EOFError Raised when the :func:`input` function hits an end-of-file condition (EOF) without reading any data. (N.B.: the :meth:`io.IOBase.read` and :meth:`io.IOBase.readline` methods return an empty string when they hit EOF.) .. exception:: FloatingPointError Raised when a floating point operation fails. This exception is always defined, but can only be raised when Python is configured with the ``--with-fpectl`` option, or the :const:`WANT_SIGFPE_HANDLER` symbol is defined in the :file:`pyconfig.h` file. .. exception:: GeneratorExit Raised when a :term:`generator` or :term:`coroutine` is closed; see :meth:`generator.close` and :meth:`coroutine.close`. It directly inherits from :exc:`BaseException` instead of :exc:`Exception` since it is technically not an error. .. exception:: ImportError Raised when the :keyword:`import` statement has troubles trying to load a module. Also raised when the "from list" in ``from ... import`` has a name that cannot be found. The :attr:`name` and :attr:`path` attributes can be set using keyword-only arguments to the constructor. When set they represent the name of the module that was attempted to be imported and the path to any file which triggered the exception, respectively. .. versionchanged:: 3.3 Added the :attr:`name` and :attr:`path` attributes. .. exception:: ModuleNotFoundError A subclass of :exc:`ImportError` which is raised by :keyword:`import` when a module could not be located. It is also raised when ``None`` is found in :data:`sys.modules`. .. versionadded:: 3.6 .. exception:: IndexError Raised when a sequence subscript is out of range. (Slice indices are silently truncated to fall in the allowed range; if an index is not an integer, :exc:`TypeError` is raised.) .. XXX xref to sequences .. exception:: KeyError Raised when a mapping (dictionary) key is not found in the set of existing keys. .. XXX xref to mapping objects? .. exception:: KeyboardInterrupt Raised when the user hits the interrupt key (normally :kbd:`Control-C` or :kbd:`Delete`). During execution, a check for interrupts is made regularly. The exception inherits from :exc:`BaseException` so as to not be accidentally caught by code that catches :exc:`Exception` and thus prevent the interpreter from exiting. .. exception:: MemoryError Raised when an operation runs out of memory but the situation may still be rescued (by deleting some objects). The associated value is a string indicating what kind of (internal) operation ran out of memory. Note that because of the underlying memory management architecture (C's :c:func:`malloc` function), the interpreter may not always be able to completely recover from this situation; it nevertheless raises an exception so that a stack traceback can be printed, in case a run-away program was the cause. .. exception:: NameError Raised when a local or global name is not found. This applies only to unqualified names. The associated value is an error message that includes the name that could not be found. .. exception:: NotImplementedError This exception is derived from :exc:`RuntimeError`. In user defined base classes, abstract methods should raise this exception when they require derived classes to override the method, or while the class is being developed to indicate that the real implementation still needs to be added. .. note:: It should not be used to indicate that an operator or method is not meant to be supported at all -- in that case either leave the operator / method undefined or, if a subclass, set it to :data:`None`. .. note:: ``NotImplementedError`` and ``NotImplemented`` are not interchangeable, even though they have similar names and purposes. See :data:`NotImplemented` for details on when to use it. .. exception:: OSError([arg]) OSError(errno, strerror[, filename[, winerror[, filename2]]]) .. index:: module: errno This exception is raised when a system function returns a system-related error, including I/O failures such as "file not found" or "disk full" (not for illegal argument types or other incidental errors). The second form of the constructor sets the corresponding attributes, described below. The attributes default to :const:`None` if not specified. For backwards compatibility, if three arguments are passed, the :attr:`~BaseException.args` attribute contains only a 2-tuple of the first two constructor arguments. The constructor often actually returns a subclass of :exc:`OSError`, as described in `OS exceptions`_ below. The particular subclass depends on the final :attr:`.errno` value. This behaviour only occurs when constructing :exc:`OSError` directly or via an alias, and is not inherited when subclassing. .. attribute:: errno A numeric error code from the C variable :c:data:`errno`. .. attribute:: winerror Under Windows, this gives you the native Windows error code. The :attr:`.errno` attribute is then an approximate translation, in POSIX terms, of that native error code. Under Windows, if the *winerror* constructor argument is an integer, the :attr:`.errno` attribute is determined from the Windows error code, and the *errno* argument is ignored. On other platforms, the *winerror* argument is ignored, and the :attr:`winerror` attribute does not exist. .. attribute:: strerror The corresponding error message, as provided by the operating system. It is formatted by the C functions :c:func:`perror` under POSIX, and :c:func:`FormatMessage` under Windows. .. attribute:: filename filename2 For exceptions that involve a file system path (such as :func:`open` or :func:`os.unlink`), :attr:`filename` is the file name passed to the function. For functions that involve two file system paths (such as :func:`os.rename`), :attr:`filename2` corresponds to the second file name passed to the function. .. versionchanged:: 3.3 :exc:`EnvironmentError`, :exc:`IOError`, :exc:`WindowsError`, :exc:`socket.error`, :exc:`select.error` and :exc:`mmap.error` have been merged into :exc:`OSError`, and the constructor may return a subclass. .. versionchanged:: 3.4 The :attr:`filename` attribute is now the original file name passed to the function, instead of the name encoded to or decoded from the filesystem encoding. Also, the *filename2* constructor argument and attribute was added. .. exception:: OverflowError Raised when the result of an arithmetic operation is too large to be represented. This cannot occur for integers (which would rather raise :exc:`MemoryError` than give up). However, for historical reasons, OverflowError is sometimes raised for integers that are outside a required range. Because of the lack of standardization of floating point exception handling in C, most floating point operations are not checked. .. exception:: RecursionError This exception is derived from :exc:`RuntimeError`. It is raised when the interpreter detects that the maximum recursion depth (see :func:`sys.getrecursionlimit`) is exceeded. .. versionadded:: 3.5 Previously, a plain :exc:`RuntimeError` was raised. .. exception:: ReferenceError This exception is raised when a weak reference proxy, created by the :func:`weakref.proxy` function, is used to access an attribute of the referent after it has been garbage collected. For more information on weak references, see the :mod:`weakref` module. .. exception:: RuntimeError Raised when an error is detected that doesn't fall in any of the other categories. The associated value is a string indicating what precisely went wrong. .. exception:: StopIteration Raised by built-in function :func:`next` and an :term:`iterator`\'s :meth:`~iterator.__next__` method to signal that there are no further items produced by the iterator. The exception object has a single attribute :attr:`value`, which is given as an argument when constructing the exception, and defaults to :const:`None`. When a :term:`generator` or :term:`coroutine` function returns, a new :exc:`StopIteration` instance is raised, and the value returned by the function is used as the :attr:`value` parameter to the constructor of the exception. If a generator function defined in the presence of a ``from __future__ import generator_stop`` directive raises :exc:`StopIteration`, it will be converted into a :exc:`RuntimeError` (retaining the :exc:`StopIteration` as the new exception's cause). .. versionchanged:: 3.3 Added ``value`` attribute and the ability for generator functions to use it to return a value. .. versionchanged:: 3.5 Introduced the RuntimeError transformation. .. exception:: StopAsyncIteration Must be raised by :meth:`__anext__` method of an :term:`asynchronous iterator` object to stop the iteration. .. versionadded:: 3.5 .. exception:: SyntaxError Raised when the parser encounters a syntax error. This may occur in an :keyword:`import` statement, in a call to the built-in functions :func:`exec` or :func:`eval`, or when reading the initial script or standard input (also interactively). Instances of this class have attributes :attr:`filename`, :attr:`lineno`, :attr:`offset` and :attr:`text` for easier access to the details. :func:`str` of the exception instance returns only the message. .. exception:: IndentationError Base class for syntax errors related to incorrect indentation. This is a subclass of :exc:`SyntaxError`. .. exception:: TabError Raised when indentation contains an inconsistent use of tabs and spaces. This is a subclass of :exc:`IndentationError`. .. exception:: SystemError Raised when the interpreter finds an internal error, but the situation does not look so serious to cause it to abandon all hope. The associated value is a string indicating what went wrong (in low-level terms). You should report this to the author or maintainer of your Python interpreter. Be sure to report the version of the Python interpreter (``sys.version``; it is also printed at the start of an interactive Python session), the exact error message (the exception's associated value) and if possible the source of the program that triggered the error. .. exception:: SystemExit This exception is raised by the :func:`sys.exit` function. It inherits from :exc:`BaseException` instead of :exc:`Exception` so that it is not accidentally caught by code that catches :exc:`Exception`. This allows the exception to properly propagate up and cause the interpreter to exit. When it is not handled, the Python interpreter exits; no stack traceback is printed. The constructor accepts the same optional argument passed to :func:`sys.exit`. If the value is an integer, it specifies the system exit status (passed to C's :c:func:`exit` function); if it is ``None``, the exit status is zero; if it has another type (such as a string), the object's value is printed and the exit status is one. A call to :func:`sys.exit` is translated into an exception so that clean-up handlers (:keyword:`finally` clauses of :keyword:`try` statements) can be executed, and so that a debugger can execute a script without running the risk of losing control. The :func:`os._exit` function can be used if it is absolutely positively necessary to exit immediately (for example, in the child process after a call to :func:`os.fork`). .. attribute:: code The exit status or error message that is passed to the constructor. (Defaults to ``None``.) .. exception:: TypeError Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch. This exception may be raised by user code to indicate that an attempted operation on an object is not supported, and is not meant to be. If an object is meant to support a given operation but has not yet provided an implementation, :exc:`NotImplementedError` is the proper exception to raise. Passing arguments of the wrong type (e.g. passing a :class:`list` when an :class:`int` is expected) should result in a :exc:`TypeError`, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a :exc:`ValueError`. .. exception:: UnboundLocalError Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable. This is a subclass of :exc:`NameError`. .. exception:: UnicodeError Raised when a Unicode-related encoding or decoding error occurs. It is a subclass of :exc:`ValueError`. :exc:`UnicodeError` has attributes that describe the encoding or decoding error. For example, ``err.object[err.start:err.end]`` gives the particular invalid input that the codec failed on. .. attribute:: encoding The name of the encoding that raised the error. .. attribute:: reason A string describing the specific codec error. .. attribute:: object The object the codec was attempting to encode or decode. .. attribute:: start The first index of invalid data in :attr:`object`. .. attribute:: end The index after the last invalid data in :attr:`object`. .. exception:: UnicodeEncodeError Raised when a Unicode-related error occurs during encoding. It is a subclass of :exc:`UnicodeError`. .. exception:: UnicodeDecodeError Raised when a Unicode-related error occurs during decoding. It is a subclass of :exc:`UnicodeError`. .. exception:: UnicodeTranslateError Raised when a Unicode-related error occurs during translating. It is a subclass of :exc:`UnicodeError`. .. exception:: ValueError Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as :exc:`IndexError`. .. exception:: ZeroDivisionError Raised when the second argument of a division or modulo operation is zero. The associated value is a string indicating the type of the operands and the operation. The following exceptions are kept for compatibility with previous versions; starting from Python 3.3, they are aliases of :exc:`OSError`. .. exception:: EnvironmentError .. exception:: IOError .. exception:: WindowsError Only available on Windows. OS exceptions ^^^^^^^^^^^^^ The following exceptions are subclasses of :exc:`OSError`, they get raised depending on the system error code. .. exception:: BlockingIOError Raised when an operation would block on an object (e.g. socket) set for non-blocking operation. Corresponds to :c:data:`errno` ``EAGAIN``, ``EALREADY``, ``EWOULDBLOCK`` and ``EINPROGRESS``. In addition to those of :exc:`OSError`, :exc:`BlockingIOError` can have one more attribute: .. attribute:: characters_written An integer containing the number of characters written to the stream before it blocked. This attribute is available when using the buffered I/O classes from the :mod:`io` module. .. exception:: ChildProcessError Raised when an operation on a child process failed. Corresponds to :c:data:`errno` ``ECHILD``. .. exception:: ConnectionError A base class for connection-related issues. Subclasses are :exc:`BrokenPipeError`, :exc:`ConnectionAbortedError`, :exc:`ConnectionRefusedError` and :exc:`ConnectionResetError`. .. exception:: BrokenPipeError A subclass of :exc:`ConnectionError`, raised when trying to write on a pipe while the other end has been closed, or trying to write on a socket which has been shutdown for writing. Corresponds to :c:data:`errno` ``EPIPE`` and ``ESHUTDOWN``. .. exception:: ConnectionAbortedError A subclass of :exc:`ConnectionError`, raised when a connection attempt is aborted by the peer. Corresponds to :c:data:`errno` ``ECONNABORTED``. .. exception:: ConnectionRefusedError A subclass of :exc:`ConnectionError`, raised when a connection attempt is refused by the peer. Corresponds to :c:data:`errno` ``ECONNREFUSED``. .. exception:: ConnectionResetError A subclass of :exc:`ConnectionError`, raised when a connection is reset by the peer. Corresponds to :c:data:`errno` ``ECONNRESET``. .. exception:: FileExistsError Raised when trying to create a file or directory which already exists. Corresponds to :c:data:`errno` ``EEXIST``. .. exception:: FileNotFoundError Raised when a file or directory is requested but doesn't exist. Corresponds to :c:data:`errno` ``ENOENT``. .. exception:: InterruptedError Raised when a system call is interrupted by an incoming signal. Corresponds to :c:data:`errno` :py:data:`~errno.EINTR`. .. versionchanged:: 3.5 Python now retries system calls when a syscall is interrupted by a signal, except if the signal handler raises an exception (see :pep:`475` for the rationale), instead of raising :exc:`InterruptedError`. .. exception:: IsADirectoryError Raised when a file operation (such as :func:`os.remove`) is requested on a directory. Corresponds to :c:data:`errno` ``EISDIR``. .. exception:: NotADirectoryError Raised when a directory operation (such as :func:`os.listdir`) is requested on something which is not a directory. Corresponds to :c:data:`errno` ``ENOTDIR``. .. exception:: PermissionError Raised when trying to run an operation without the adequate access rights - for example filesystem permissions. Corresponds to :c:data:`errno` ``EACCES`` and ``EPERM``. .. exception:: ProcessLookupError Raised when a given process doesn't exist. Corresponds to :c:data:`errno` ``ESRCH``. .. exception:: TimeoutError Raised when a system function timed out at the system level. Corresponds to :c:data:`errno` ``ETIMEDOUT``. .. versionadded:: 3.3 All the above :exc:`OSError` subclasses were added. .. seealso:: :pep:`3151` - Reworking the OS and IO exception hierarchy Warnings -------- The following exceptions are used as warning categories; see the :mod:`warnings` module for more information. .. exception:: Warning Base class for warning categories. .. exception:: UserWarning Base class for warnings generated by user code. .. exception:: DeprecationWarning Base class for warnings about deprecated features. .. exception:: PendingDeprecationWarning Base class for warnings about features which will be deprecated in the future. .. exception:: SyntaxWarning Base class for warnings about dubious syntax. .. exception:: RuntimeWarning Base class for warnings about dubious runtime behavior. .. exception:: FutureWarning Base class for warnings about constructs that will change semantically in the future. .. exception:: ImportWarning Base class for warnings about probable mistakes in module imports. .. exception:: UnicodeWarning Base class for warnings related to Unicode. .. exception:: BytesWarning Base class for warnings related to :class:`bytes` and :class:`bytearray`. .. exception:: ResourceWarning Base class for warnings related to resource usage. .. versionadded:: 3.2 Exception hierarchy ------------------- The class hierarchy for built-in exceptions is: .. literalinclude:: ../../Lib/test/exception_hierarchy.txt
Save
cmd:
run