Lines Matching full:exception
12 clause that mentions a particular class, that clause also handles any exception
13 classes derived from that class (but not exception classes from which *it* is
14 derived). Two exception classes that are not related via subclassing are never
23 code). The associated value is usually passed as arguments to the exception
26 User code can raise built-in exceptions. This can be used to test an exception
28 interpreter raises the same exception; but beware that there is nothing to
31 The built-in exception classes can be subclassed to define new exceptions;
32 programmers are encouraged to derive new exceptions from the :exc:`Exception`
38 Exception context
41 .. index:: pair: exception; chaining
42 __cause__ (exception attribute)
43 __context__ (exception attribute)
44 __suppress_context__ (exception attribute)
46 Three attributes on exception objects provide information about the context in
47 which the exception was raised:
53 When raising a new exception while another exception
54 is already being handled, the new exception's
56 exception. An exception may be handled when an :keyword:`except` or
59 This implicit exception context can be
65 The expression following :keyword:`from<raise>` must be an exception or ``None``. It
66 will be set as :attr:`!__cause__` on the raised exception. Setting
69 effectively replaces the old exception with the new one for display
71 leaving the old exception available in :attr:`!__context__` for introspection
75 addition to the traceback for the exception itself. An explicitly chained
76 exception in :attr:`!__cause__` is always shown when present. An implicitly
77 chained exception in :attr:`!__context__` is shown only if :attr:`!__cause__`
80 In either case, the exception itself is always shown after any chained
82 exception that was raised.
88 User code can create subclasses that inherit from an exception type.
89 It's recommended to only subclass one exception type at a time to avoid
98 multiple exception types. The memory layout of a type is an implementation
101 subclassing multiple exception types altogether.
109 .. exception:: BaseException
112 inherited by user-defined classes (for that, use :exc:`Exception`). If
119 The tuple of arguments given to the exception constructor. Some built-in
126 This method sets *tb* as the new traceback for the exception and returns
127 the exception object. It was more commonly used before the exception
138 tb = sys.exception().__traceback__
145 exception. See also: :ref:`raise`.
149 Add the string ``note`` to the exception's notes which appear in the standard
150 traceback after the exception string. A :exc:`TypeError` is raised if ``note``
157 A list of the notes of this exception, which were added with :meth:`add_note`.
163 .. exception:: Exception
169 .. exception:: ArithmeticError
176 .. exception:: BufferError
182 .. exception:: LookupError
194 .. exception:: AssertionError
201 .. exception:: AttributeError
215 .. exception:: EOFError
222 .. exception:: FloatingPointError
227 .. exception:: GeneratorExit
231 directly inherits from :exc:`BaseException` instead of :exc:`Exception` since
235 .. exception:: ImportError
250 The path to any file which triggered the exception.
255 .. exception:: ModuleNotFoundError
264 .. exception:: IndexError
273 .. exception:: KeyError
280 .. exception:: KeyboardInterrupt
284 regularly. The exception inherits from :exc:`BaseException` so as to not be
285 accidentally caught by code that catches :exc:`Exception` and thus prevent
298 .. exception:: MemoryError
305 nevertheless raises an exception so that a stack traceback can be printed, in
309 .. exception:: NameError
323 .. exception:: NotImplementedError
325 This exception is derived from :exc:`RuntimeError`. In user defined base
326 classes, abstract methods should raise this exception when they require
342 .. exception:: OSError([arg])
347 This exception is raised when a system function returns a system-related
409 .. exception:: OverflowError
415 range. Because of the lack of standardization of floating-point exception
419 .. exception:: PythonFinalizationError
421 This exception is derived from :exc:`RuntimeError`. It is raised when
437 .. exception:: RecursionError
439 This exception is derived from :exc:`RuntimeError`. It is raised when the
447 .. exception:: ReferenceError
449 This exception is raised when a weak reference proxy, created by the
455 .. exception:: RuntimeError
462 .. exception:: StopIteration
470 The exception object has a single attribute :attr:`!value`, which is
471 given as an argument when constructing the exception, and defaults
477 :attr:`value` parameter to the constructor of the exception.
481 :exc:`StopIteration` as the new exception's cause).
495 .. exception:: StopAsyncIteration
502 .. exception:: SyntaxError(message, details)
510 The :func:`str` of the exception instance returns only the error message.
549 .. exception:: IndentationError
555 .. exception:: TabError
561 .. exception:: SystemError
570 message (the exception's associated value) and if possible the source of the
574 .. exception:: SystemExit
576 This exception is raised by the :func:`sys.exit` function. It inherits from
577 :exc:`BaseException` instead of :exc:`Exception` so that it is not accidentally
578 caught by code that catches :exc:`Exception`. This allows the exception to
587 A call to :func:`sys.exit` is translated into an exception so that clean-up
600 .. exception:: TypeError
605 This exception may be raised by user code to indicate that an attempted
608 implementation, :exc:`NotImplementedError` is the proper exception to raise.
615 .. exception:: UnboundLocalError
622 .. exception:: UnicodeError
652 .. exception:: UnicodeEncodeError
658 .. exception:: UnicodeDecodeError
664 .. exception:: UnicodeTranslateError
670 .. exception:: ValueError
674 more precise exception such as :exc:`IndexError`.
677 .. exception:: ZeroDivisionError
687 .. exception:: EnvironmentError
689 .. exception:: IOError
691 .. exception:: WindowsError
702 .. exception:: BlockingIOError
718 .. exception:: ChildProcessError
723 .. exception:: ConnectionError
730 .. exception:: BrokenPipeError
737 .. exception:: ConnectionAbortedError
743 .. exception:: ConnectionRefusedError
749 .. exception:: ConnectionResetError
755 .. exception:: FileExistsError
760 .. exception:: FileNotFoundError
765 .. exception:: InterruptedError
772 signal, except if the signal handler raises an exception (see :pep:`475`
775 .. exception:: IsADirectoryError
781 .. exception:: NotADirectoryError
789 .. exception:: PermissionError
800 .. exception:: ProcessLookupError
805 .. exception:: TimeoutError
816 :pep:`3151` - Reworking the OS and IO exception hierarchy
827 .. exception:: Warning
832 .. exception:: UserWarning
837 .. exception:: DeprecationWarning
849 .. exception:: PendingDeprecationWarning
865 .. exception:: SyntaxWarning
870 .. exception:: RuntimeWarning
875 .. exception:: FutureWarning
881 .. exception:: ImportWarning
889 .. exception:: UnicodeWarning
894 .. exception:: EncodingWarning
903 .. exception:: BytesWarning
908 .. exception:: ResourceWarning
918 .. _lib-exception-groups:
920 Exception groups
924 exceptions. They are part of the exception hierarchy so they can be
929 .. exception:: ExceptionGroup(msg, excs)
930 .. exception:: BaseExceptionGroup(msg, excs)
932 Both of these exception types wrap the exceptions in the sequence ``excs``.
935 it can wrap any exception, while :exc:`ExceptionGroup` extends :exc:`Exception`
936 and it can only wrap subclasses of :exc:`Exception`. This design is so that
937 ``except Exception`` catches an :exc:`ExceptionGroup` but not
942 :exc:`Exception` instances, so it can be used to make the selection
944 raises a :exc:`TypeError` if any contained exception is not an
945 :exc:`Exception` subclass.
958 Returns an exception group that contains only the exceptions from the
961 The condition can be an exception type or tuple of exception types, in which
962 case each exception is checked for a match using the same check that is used
964 a type object) that accepts an exception as its single argument and returns
967 The nesting structure of the current exception is preserved in the result,
974 The condition is checked for all exceptions in the nested exception group,
975 including the top-level and any nested exception groups. If the condition is
976 true for such an exception group, it is included in the result in full.
989 Returns an exception group with the same :attr:`message`, but which
993 are used in various contexts to break up an exception group. A
1002 the original exception group to the one returned by :meth:`derive`, so
1013 >>> e.__context__ = Exception("context")
1014 >>> e.__cause__ = Exception("cause")
1017 ... except Exception as e:
1022 …(MyGroup('eg', [ValueError(1), TypeError(2)]), Exception('context'), Exception('cause'), ['a note'…
1024 (MyGroup('eg', [ValueError(1)]), Exception('context'), Exception('cause'), ['a note'])
1026 (MyGroup('eg', [TypeError(2)]), Exception('context'), Exception('cause'), ['a note'])
1034 defines an exception group subclass which accepts an exit_code and
1047 is also a subclass of :exc:`Exception` can only wrap instances of
1048 :exc:`Exception`.
1053 Exception hierarchy