Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77a6b20

Browse files
committed
Issue #23432: Remove duplicate content from SystemExit docs.
Also, document SystemExit.code attribute explicitly.
1 parent 47c41b4 commit 77a6b20

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

Doc/library/exceptions.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,28 +353,28 @@ The following exceptions are the exceptions that are usually raised.
353353

354354
.. exception:: SystemExit
355355

356-
This exception is raised by the :func:`sys.exit` function. When it is not
357-
handled, the Python interpreter exits; no stack traceback is printed. If the
358-
associated value is an integer, it specifies the system exit status (passed
359-
to C's :c:func:`exit` function); if it is ``None``, the exit status is zero;
360-
if it has another type (such as a string), the object's value is printed and
356+
This exception is raised by the :func:`sys.exit` function. It inherits from
357+
:exc:`BaseException` instead of :exc:`Exception` so that it is not accidentally
358+
caught by code that catches :exc:`Exception`. This allows the exception to
359+
properly propagate up and cause the interpreter to exit. When it is not
360+
handled, the Python interpreter exits; no stack traceback is printed. The
361+
constructor accepts the same optional argument passed to :func:`sys.exit`.
362+
If the value is an integer, it specifies the system exit status (passed to
363+
C's :c:func:`exit` function); if it is ``None``, the exit status is zero; if
364+
it has another type (such as a string), the object's value is printed and
361365
the exit status is one.
362366

363-
Instances have an attribute :attr:`!code` which is set to the proposed exit
364-
status or error message (defaulting to ``None``). Also, this exception derives
365-
directly from :exc:`BaseException` and not :exc:`Exception`, since it is not
366-
technically an error.
367-
368367
A call to :func:`sys.exit` is translated into an exception so that clean-up
369368
handlers (:keyword:`finally` clauses of :keyword:`try` statements) can be
370369
executed, and so that a debugger can execute a script without running the risk
371370
of losing control. The :func:`os._exit` function can be used if it is
372371
absolutely positively necessary to exit immediately (for example, in the child
373372
process after a call to :func:`os.fork`).
374373

375-
The exception inherits from :exc:`BaseException` instead of :exc:`Exception` so
376-
that it is not accidentally caught by code that catches :exc:`Exception`. This
377-
allows the exception to properly propagate up and cause the interpreter to exit.
374+
.. attribute:: code
375+
376+
The exit status or error message that is passed to the constructor.
377+
(Defaults to ``None``.)
378378

379379

380380
.. exception:: TypeError

0 commit comments

Comments
 (0)