blob: bcd3599477f74ade94d51935dade539568c9bda6 [file] [log] [blame]
Yury Selivanov7c7605f2018-09-11 09:54:40 -07001.. currentmodule:: asyncio
2
3
4==========
5Exceptions
6==========
7
8
9.. exception:: TimeoutError
10
11 The operation has exceeded the given deadline.
12
13 .. note::
14 This exception is different from the builtin :exc:`TimeoutError`
15 exception.
16
17
18.. exception:: CancelledError
19
20 The operation has been cancelled.
21
22 This exception can be caught to perform custom operations on
23 when asyncio Tasks are cancelled. In almost all situations the
24 exception must always be re-raised.
25
26 .. note::
27 This exception is a subclass of :exc:`Exception`, so it can be
28 accidentally suppressed by ``try..except`` block::
29
30 try:
31 await operation
32 except Exception:
33 # The cancellation is broken because the *except* block
34 # suppresses the CancelledError exception.
35 log.log('an error has occurred')
36
37 Instead, the following pattern should be used::
38
39 try:
40 await operation
41 except asyncio.CancelledError:
42 raise
43 except Exception:
44 log.log('an error has occurred')
45
46
47.. exception:: InvalidStateError
48
49 Invalid internal state of :class:`Task` or :class:`Future`.
50
51 Can be raised in situations like setting a result value for a
52 *Future* object that already has a result value set.
53
54
55.. exception:: SendfileNotAvailableError
56
57 The "sendfile" syscall for is not available for the given
58 socket or file type.
59
60 A subclass of :exc:`RuntimeError`.
61
62
63.. exception:: IncompleteReadError
64
65 Incomplete read error.
66
67 Raised by :ref:`asyncio streams <asyncio-streams>` APIs.
68
69 This exception is a subclass of :exc:`EOFError`.
70
71 .. attribute:: expected
72
73 Total number (:class:`int`) of expected bytes.
74
75 .. attribute:: partial
76
77 Read :class:`bytes` string before the end of stream was reached.
78
79
80.. exception:: LimitOverrunError
81
82 Reached the buffer limit while looking for a separator.
83
84 Raised by :ref:`asyncio streams <asyncio-streams>` APIs.
85
86 .. attribute:: consumed
87
88 Total number of to be consumed bytes.