.. _bltin-exceptions:

組み込み例外
============

.. module:: exceptions
   :synopsis: 標準の例外クラス群


.. Exceptions should be class objects.   The exceptions are defined in the module
.. :mod:`exceptions`.  This module never needs to be imported explicitly: the
.. exceptions are provided in the built-in namespace as well as the
.. :mod:`exceptions` module.

例外はクラスオブジェクトです。例外はモジュール :mod:`exceptions`
で定義されています。このモジュールを明示的にインポートする必要はありません。
例外は :mod:`exceptions` モジュールと同様に組み込み名前空間で与えられます。


.. index::
   statement: try
   statement: except


.. For class exceptions, 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.

:keyword:`try` 文の中で、 :keyword:`except` 節を使って特定の例外クラス
について記述した場合、その節は指定した例外クラスから派生したクラスも
扱います (指定した例外クラスの派生元のクラスは含みません)。
サブクラス化の関係にない 2 つの例外クラスは、それらが同じ名前だったとしても
等しくなることはありません。


.. 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
.. containing several items of information (e.g., an error code and a string
.. explaining the code). The associated value is the second argument to the
.. :keyword:`raise` statement.  If the exception class is derived from the standard
.. root class :exc:`BaseException`, the associated value is present as the
.. exception instance's :attr:`args` attribute.

以下に列挙した組み込み例外はインタプリタや組み込み関数によって生成され
ます。特に注記しないかぎり、これらの例外はエラーの詳しい原因を示してい
る、 "関連値 (associated value)" を持ちます。この値は文字列または複数
の情報 (例えばエラーコードや、エラーコードを説明する文字列) を含むタプ
ルです。この関連値は :keyword:`raise` 文の 2 番目の引数です。
例外が標準のルートクラスである :exc:`BaseException` の派生クラスであれば、
関連値は例外インスタンスの :attr:`args` 属性中に置かれます。


.. 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 sub-classed to define new exceptions;
.. programmers are encouraged to at least derive new exceptions from the
.. :exc:`Exception` class and not :exc:`BaseException`.  More information on
.. defining exceptions is available in the Python Tutorial under
.. :ref:`tut-userexceptions`.

組み込み例外クラスは新たな例外を定義するためにサブクラス化することができます。
新しい例外は、少なくとも :exc:`Exception` クラスから派生することをお勧めします。
:exc:`BaseException` からは派生しないで下さい。例外を定義する上での詳しい情報は、
Python チュートリアルの :ref:`tut-userexceptions` の項目にあります。


.. The following exceptions are only used 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` or :func:`unicode` 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.  All arguments are  stored in :attr:`args`
   .. as a tuple.

   全ての組み込み例外のルートクラスです。ユーザ定義例外が直接このクラ
   スを継承することは意図していません (そうした場合は
   :exc:`Exception` を使ってください)。このクラスに対して :func:`str`
   や :func:`unicode` が呼ばれた場合、引数の文字列表現かまたは引数が無
   い時には空文字列が返されます。
   全ての引数はタプルとして :attr:`args` に格納されます。


   .. versionadded:: 2.5


.. 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.

   全ての組み込み例外のうち、システム終了でないものはこのクラスから導
   出されています。全てのユーザ定義例外はこのクラスの派生クラスであるべき
   です。


   .. .. versionchanged:: 2.5
   ..    .. Changed to inherit from :exc:`BaseException`.

   .. versionchanged:: 2.5
      :exc:`BaseException` を継承するように変更されました.


.. exception:: StandardError

   .. The base class for all built-in exceptions except :exc:`StopIteration`,
   .. :exc:`GeneratorExit`, :exc:`KeyboardInterrupt` and :exc:`SystemExit`.
   .. :exc:`StandardError` itself is derived from :exc:`Exception`.

   :exc:`StopIteration`, :exc:`SystemExit`, :exc:`KeyboardInterrupt`,
   :exc:`SystemExit` 以外の、全ての組み込み例外の基底クラスです。
   :exc:`StandardError` 自体は :exc:`Exception` の派生クラスです。


.. exception:: ArithmeticError

   .. The base class for those built-in exceptions that are raised for various
   .. arithmetic errors: :exc:`OverflowError`, :exc:`ZeroDivisionError`,
   .. :exc:`FloatingPointError`.

   算術上の様々なエラーにおいて送出される組み込み例外
   :exc:`OverflowError`, :exc:`ZeroDivisionError`,
   :exc:`FloatingPointError` の基底クラスです。


.. 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`.

   マップ型またはシーケンス型に使われたキーやインデックスが無効な場合
   に送出される例外 :exc:`IndexError` および :exc:`KeyError` の基底クラス
   です。 :func:`codecs.lookup` によって直接送出されることもあります。


.. exception:: EnvironmentError

   .. The base class for exceptions that can occur outside the Python system:
   .. :exc:`IOError`, :exc:`OSError`.  When exceptions of this type are created with a
   .. 2-tuple, the first item is available on the instance's :attr:`errno` attribute
   .. (it is assumed to be an error number), and the second item is available on the
   .. :attr:`strerror` attribute (it is usually the associated error message).  The
   .. tuple itself is also available on the :attr:`args` attribute.

   Python システムの外部で起こる可能性のある例外 :exc:`IOError` および
   :exc:`OSError` の基底クラスです。この型の例外が 2 つの要素を持つ
   タプルで生成された場合、 1 番目の要素はインスタンスの :attr:`errno`
   属性で得ることができます (この値はエラー番号と見なされます)。 2 番目
   の要素は :attr:`strerror` 属性です (この値は通常、エラーに関連する
   メッセージです)。タプル自体は :attr:`args` 属性から得ることもできます。


   .. versionadded:: 1.5.2

   .. When an :exc:`EnvironmentError` exception is instantiated with a 3-tuple, the
   .. first two items are available as above, while the third item is available on the
   .. :attr:`filename` attribute.  However, for backwards compatibility, the
   .. :attr:`args` attribute contains only a 2-tuple of the first two constructor
   .. arguments.

   :exc:`EnvironmentError` 例外が 3 要素のタプルで生成された場合、最初
   の 2 つの要素は上記と同様に値を得ることができ、さらに 3 番目の要素は
   :attr:`filename` 属性で得ることができます。しかしながら、以前のバー
   ジョンとの互換性のために、 :attr:`args` 属性にはコンストラクタに渡
   した最初の 2 つの引数からなる 2 要素のタプルしか含みません。


   .. The :attr:`filename` attribute is ``None`` when this exception is created with
   .. other than 3 arguments.  The :attr:`errno` and :attr:`strerror` attributes are
   .. also ``None`` when the instance was created with other than 2 or 3 arguments.
   .. In this last case, :attr:`args` contains the verbatim constructor arguments as a
   .. tuple.

   この例外が 3 つ以外の引数で生成された場合、 :attr:`filename` 属性は
   ``None`` になります。この例外が 2 つまたは 3 つ以外の引数で生成された
   場合、 :attr:`errno` および :attr:`strerror` 属性も ``None`` になり
   ます。後者のケースでは、 :attr:`args` がコンストラクタに与えた引数
   をそのままタプルの形で含んでいます。


.. The following exceptions are the exceptions that are actually raised.

以下の例外は実際に送出される例外です。


.. exception:: AssertionError

   .. index:: statement: assert

   .. Raised when an :keyword:`assert` statement fails.

   :keyword:`assert` 文が失敗した場合に送出されます。


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

   属性の参照 (:ref:`attribute-references` を参照) や代入が失敗
   した場合に送出されます (オブジェクトが属性の参照や属性の代入をまっ
   たくサポートしていない場合には :exc:`TypeError` が送出されます)。


.. exception:: EOFError

   .. Raised when one of the built-in functions (:func:`input` or :func:`raw_input`)
   .. hits an end-of-file condition (EOF) without reading any data. (N.B.: the
   .. :meth:`file.read` and :meth:`file.readline` methods return an empty string
   .. when they hit EOF.)

   組み込み関数 (:func:`input` または :func:`raw_input`) のいずれかで、
   データを全く読まないうちにファイルの終端 (EOF) に到達した場合に送出
   されます (注意: :meth:`file.read` および :meth:`file.readline` メソッド
   の場合、データを読まないうちに 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
   .. :option:`--with-fpectl` option, or the :const:`WANT_SIGFPE_HANDLER` symbol is
   .. defined in the :file:`pyconfig.h` file.

   浮動小数点演算が失敗した場合に送出されます。この例外は Python
   のどのバージョンでも常に定義されていますが、 Python が
   :option:`--with-fpectl` オプションを有効にしてコンパイルされているか、
   :file:`pyconfig.h` ファイルにシンボル :const:`WANT_SIGFPE_HANDLER`
   が定義されている場合にのみ送出されます。


.. exception:: GeneratorExit

   .. Raise when a :term:`generator`\'s :meth:`close` method is called.  It
   .. directly inherits from :exc:`BaseException` instead of :exc:`StandardError` since
   .. it is technically not an error.

   ジェネレータ (:term:`generator`) の :meth:`close` メソッドが呼び出
   されたときに送出されます。この例外は厳密にはエラーではないので、
   :exc:`StandardError` ではなく :exc:`BaseException` を直接継承しています。


   .. versionadded:: 2.5

   .. .. versionchanged:: 2.6
   ..    .. Changed to inherit from :exc:`BaseException`.

   .. versionchanged:: 2.6
      :exc:`BaseException` を継承するように変更されました。


.. exception:: IOError

   .. Raised when an I/O operation (such as a :keyword:`print` statement, the built-in
   .. :func:`open` function or a method of a file object) fails for an I/O-related
   .. reason, e.g., "file not found" or "disk full".

   (:keyword:`print` 文、組み込みの :func:`open` またはファイルオブジェ
   クトに対するメソッドといった) I/O 操作が、例えば "ファイルが存在し
   ません" や "ディスクの空き領域がありません" といった I/O に関連した
   理由で失敗した場合に送出されます。


   .. This class is derived from :exc:`EnvironmentError`.  See the discussion above
   .. for more information on exception instance attributes.

   このクラスは :exc:`EnvironmentError` の派生クラスです。この例外
   クラスのインスタンス属性に関する情報は上記の
   :exc:`EnvironmentError` に関する議論を参照してください。


   .. .. versionchanged:: 2.6
   ..    .. Changed :exc:`socket.error` to use this as a base class.

   .. versionchanged:: 2.6
      :exc:`socket.error` は、この例外を基底クラスとして使うように変更されました。


.. exception:: ImportError

   .. Raised when an :keyword:`import` statement fails to find the module definition
   .. or when a ``from ... import`` fails to find a name that is to be imported.

   :keyword:`import` 文でモジュール定義を見つけられなかった場合や、
   ``from ... import`` 文で指定した名前をインポートすることができなかった場合に送出されます。


.. 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 a plain integer,
   .. :exc:`TypeError` is raised.)

   シーケンスのインデックス指定がシーケンスの範囲を超えている場合に送出
   されます　(スライスのインデックスはシーケンスの範囲に収まるように暗黙
   のうちに調整されます; インデックスが通常の整数でない場合、
   :exc:`TypeError` が送出されます)。


   .. 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.
   .. Interrupts typed when a built-in function :func:`input` or :func:`raw_input` is
   .. waiting for input also raise this exception. 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.

   ユーザが割り込みキー (通常は :kbd:`Control-C` または :kbd:`Delete` キー)
   を押した場合に送出されます。割り込みが起きたかどうかはインタプリタの
   実行中に定期的に調べられます。組み込み関数 :func:`input` や
   :func:`raw_input` がユーザの入力を待っている間に割り込みキーを押しても
   この例外が送出されます。この例外は :exc:`Exception` を処理するコードに
   誤って捕捉されてインタプリタの終了が阻害されないように :exc:`BaseException`
   を継承しています。


   .. .. versionchanged:: 2.5
   ..    .. Changed to inherit from :exc:`BaseException`.

   .. versionchanged:: 2.5
      :exc:`BaseException` を継承するように変更されました.


.. 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.

   ある操作中にメモリが不足したが、その状況は (オブジェクトをいくつか
   消去することで) まだ復旧可能かもしれない場合に送出されます。例外の
   関連値は、どんな種類の (内部) 操作がメモリ不足になっているか
   を示す文字列です。背後にあるメモリ管理アーキテクチャ (C の
   :c:func:`malloc` 関数) によっては、インタプリタが常にその状況を完璧
   に復旧できるとはかぎらないので注意してください; プログラムの暴走が
   原因の場合にも、やはり実行スタックの追跡結果を出力できるようにする
   ために例外が送出されます。


.. 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.

   この例外は :exc:`RuntimeError` から派生しています。ユーザ定義の基底
   クラスにおいて、抽象メソッドが派生クラスでオーバライドされることを
   要求する場合、この例外を送出しなくてはなりません。

   .. versionadded:: 1.5.2


.. exception:: OSError

   .. index:: module: errno

   .. This exception is derived from :exc:`EnvironmentError`.  It is raised when a
   .. function returns a system-related error (not for illegal argument types or
   .. other incidental errors).  The :attr:`errno` attribute is a numeric error
   .. code from :c:data:`errno`, and the :attr:`strerror` attribute is the
   .. corresponding string, as would be printed by the C function :c:func:`perror`.
   .. See the module :mod:`errno`, which contains names for the error codes defined
   .. by the underlying operating system.

   このクラスは :exc:`EnvironmentError` から派生しています。
   関数がシステムに関連したエラーを返した場合に送出されます
   (引数の型が間違っている場合や、他の偶発的なエラーは除きます)。
   :attr:`errno` 属性は :c:data:`errno` に基づく数字のエラーコードで、
   :attr:`strerror` 属性は C の :c:func:`perror` 関数で表示されるような
   文字列です。
   オペレーティングシステムに依存したエラーコードの定義と名前については、
   :mod:`errno` モジュールを参照して下さい。

   .. For exceptions that involve a file system path (such as :func:`chdir` or
   .. :func:`unlink`), the exception instance will contain a third attribute,
   .. :attr:`filename`, which is the file name passed to the function.

   ファイルシステムのパスに関係する例外 (:func:`chdir` や
   :func:`unlink` など) では、例外インスタンスは 3 番目の属性
   :attr:`filename` を持ちます。これは関数に渡されたファイル名です。

   .. versionadded:: 1.5.2


.. exception:: OverflowError

   .. Raised when the result of an arithmetic operation is too large to be
   .. represented.  This cannot occur for long integers (which would rather raise
   .. :exc:`MemoryError` than give up) and for most operations with plain integers,
   .. which return a long integer instead.  Because of the lack of standardization
   .. of floating point exception handling in C, most floating point operations
   .. also aren't checked.

   算術演算の結果が表現できない大きな値になった場合に送出されます。
   これは long integer の演算と通常の整数に関するほとんどの操作では
   起こりません (long integer の演算ではむしろ :exc:`MemoryError` が
   送出されることになるでしょう)。整数に関するほとんどの操作では、
   代わりに long integer が返されます。
   C の浮動小数点演算の例外処理は標準化されていないので、ほとんどの
   浮動小数点演算もチェックされません。


.. 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.

   :func:`weakref.proxy` によって生成された弱参照 (weak reference)
   プロキシを使って、ガーベジコレクションによって回収された後の参照対象
   オブジェクトの属性にアクセスした場合に送出されます。弱参照については
   :mod:`weakref` モジュールを参照してください。


   .. .. versionadded:: 2.2
   ..    .. Previously known as the :exc:`weakref.ReferenceError` exception.

   .. versionadded:: 2.2
      以前は :exc:`weakref.ReferenceError` 例外として知られていました。


.. 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.  (This exception is mostly a relic from a previous version of the
   .. interpreter; it is not used very much any more.)

   他のカテゴリに分類できないエラーが検出された場合に送出されます。
   関連値は、何が問題だったのかをより詳細に示す文字列です
   (この例外はほとんど過去のバージョンのインタプリタにおける遺物です。
   今ではあまり使われることはありません)。


.. exception:: StopIteration

   .. Raised by an :term:`iterator`\'s :meth:`~iterator.next` method to signal that
   .. there are no further values.  This is derived from :exc:`Exception` rather
   .. than :exc:`StandardError`, since this is not considered an error in its
   .. normal application.

   イテレータ (:term:`iterator`) の :meth:`~iterator.next` メソッドにより、それ
   以上要素がないことを知らせるために送出されます。
   この例外は、通常の利用方法ではエラーとはみなされないため、
   :exc:`StandardError` ではなく :exc:`Exception` から派生しています。

   .. versionadded:: 2.2


.. exception:: SyntaxError

   .. Raised when the parser encounters a syntax error.  This may occur in an
   .. :keyword:`import` statement, in an :keyword:`exec` statement, in a call to the
   .. built-in function :func:`eval` or :func:`input`, or when reading the initial
   .. script or standard input (also interactively).

   パーザが構文エラーに遭遇した場合に送出されます。この例外は
   :keyword:`import` 文、 :keyword:`exec` 文、組み込み関数
   :func:`evel` や :func:`input` 、初期化スクリプトの読み込みや標準入
   力で (対話的な実行時にも) 起こる可能性があります。


   .. 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.

   このクラスのインスタンスは、例外の詳細に簡単にアクセスできるように
   するために、属性 :attr:`filename`, :attr:`lineno`,
   :attr:`offset`, :attr:`text` を持ちます。例外インスタンスに
   対する :func:`str` はメッセージのみを返します。


.. 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.

   Python の作者か、あなたの Python インタプリタを保守している人にこの
   エラーを報告してください。このとき、 Python インタプリタのバージョン
   (``sys.version``; Python の対話的セッションを開始した際にも出力
   されます)、正確なエラーメッセージ (例外の関連値) を忘れずに報告して
   ください。そしてもし可能ならエラーを引き起こしたプログラムの
   ソースコードを報告してください。


.. exception:: SystemExit

   .. This exception is raised by the :func:`sys.exit` function.  When it is not
   .. handled, the Python interpreter exits; no stack traceback is printed.  If the
   .. associated value is a plain 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.

   この例外は :func:`sys.exit` 関数によって送出されます。この例外が
   処理されなかった場合、スタックのトレースバックを全く表示することなく
   Python インタプリタは終了します。関連値が通常の整数であれば、
   システム終了ステータスを表します (:c:func:`exit` 関数に渡されます)。
   値が ``None`` の場合、終了ステータスは 0 です。 (文字列のような) 他の
   型の場合、そのオブジェクトの値が表示され、終了ステータスは 1 になります。

   .. Instances have an attribute :attr:`code` which is set to the proposed exit
   .. status or error message (defaulting to ``None``). Also, this exception derives
   .. directly from :exc:`BaseException` and not :exc:`StandardError`, since it is not
   .. technically an error.

   この例外のインスタンスは属性 :attr:`code` を持ちます。この値は終了
   ステータスまたはエラーメッセージ (標準では ``None``) に設定されます。
   また、この例外は厳密にはエラーではないため、 :exc:`StandardError`
   ではなく :exc:`BaseException` から派生しています。


   .. 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:`fork`).

   :func:`sys.exit` は、クリーンアップのための処理 (:keyword:`try` 文の
   :keyword:`finally` 節) が実行されるようにするため、またデバッガが制
   御不能になるリスクを冒さずにスクリプトを実行できるようにするために
   例外に翻訳されます。即座に終了することが真に強く必要であるとき (例
   えば、 :func:`fork` を呼んだ後の子プロセス内) には :func:`os._exit`
   関数を使うことができます。


   .. The exception inherits from :exc:`BaseException` instead of :exc:`StandardError`
   .. or :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.

   この例外は :exc:`Exception` を捕まえるコードに間違って捕まえられな
   いように、 :exc:`StandardError` や :exc:`Exception` からではなく
   :exc:`BaseException` を継承しています。これにより、この例外は着
   実に呼出し元の方に伝わっていってインタプリタを終了させます。


   .. .. versionchanged:: 2.5
   ..    .. Changed to inherit from :exc:`BaseException`.

   .. versionchanged:: 2.5
      :exc:`BaseException` を継承するように変更されました。


.. 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.

   組み込み演算または関数が適切でない型のオブジェクトに対して適用され
   た際に送出されます。関連値は型の不整合に関して詳細を述べた文字列です。


.. 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`.

   関数やメソッド内のローカルな変数に対して参照を行ったが、その変数に
   は値が代入されていなかった場合に送出されます。 :exc:`NameError`
   のサブクラスです。

   .. versionadded:: 2.0


.. exception:: UnicodeError

   .. Raised when a Unicode-related encoding or decoding error occurs.  It is a
   .. subclass of :exc:`ValueError`.

   Unicode に関するエンコードまたはデコードのエラーが発生した際に送出
   されます。 :exc:`ValueError` のサブクラスです。

   .. versionadded:: 2.0


.. exception:: UnicodeEncodeError

   .. Raised when a Unicode-related error occurs during encoding.  It is a subclass of
   .. :exc:`UnicodeError`.

   Unicode 関連のエラーがエンコード中に発生した際に送出されます。
   :exc:`UnicodeError` のサブクラスです。

   .. versionadded:: 2.3


.. exception:: UnicodeDecodeError

   .. Raised when a Unicode-related error occurs during decoding.  It is a subclass of
   .. :exc:`UnicodeError`.

   Unicode 関連のエラーがデコード中に発生した際に送出されます。
   :exc:`UnicodeError` のサブクラスです。

   .. versionadded:: 2.3


.. exception:: UnicodeTranslateError

   .. Raised when a Unicode-related error occurs during translating.  It is a subclass
   .. of :exc:`UnicodeError`.

   Unicode 関連のエラーがコード翻訳に発生した際に送出されます。
   :exc:`UnicodeError` のサブクラスです。

   .. versionadded:: 2.3


.. exception:: ValueError

   .. Raised when a built-in 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`.

   組み込み演算や関数が、正しい型だが適切でない値を受け取った場合や、
   :exc:`IndexError` のような詳細な説明のできない状況で送出されます。


.. exception:: VMSError

   .. Only available on VMS.  Raised when a VMS-specific error occurs.

   VMS においてのみ利用可能です。 VMS 特有のエラーが起こったときに送出されます。


.. exception:: WindowsError

   .. Raised when a Windows-specific error occurs or when the error number does not
   .. correspond to an :c:data:`errno` value.  The :attr:`winerror` and
   .. :attr:`strerror` values are created from the return values of the
   .. :c:func:`GetLastError` and :c:func:`FormatMessage` functions from the Windows
   .. Platform API. The :attr:`errno` value maps the :attr:`winerror` value to
   .. corresponding ``errno.h`` values. This is a subclass of :exc:`OSError`.

   Windows 特有のエラーか、エラー番号が :c:data:`errno` 値に対応しない
   場合に送出されます。 :attr:`winerrno` および :attr:`strerror` の値は
   Windows プラットフォーム API の関数 :c:func:`GetLastError` と
   :c:func:`FormatMessage` の戻り値から生成されます。 :attr:`errno` の
   値は :attr:`winerror` の値を対応する ``errno.h`` の値にマップしたものです。
   :exc:`OSError` のサブクラスです。


   .. versionadded:: 2.0

   .. .. versionchanged:: 2.5
   ..    .. Previous versions put the :c:func:`GetLastError` codes into :attr:`errno`.

   .. versionchanged:: 2.5
      以前のバージョンは :c:func:`GetLastError` のコードを
      :attr:`errno` に入れていました。


.. 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.

   除算またモジュロ演算における 2 番目の引数が 0 であった場合に送出されます。
   関連値は文字列で、その演算における被演算子と演算子の型を示します。


.. The following exceptions are used as warning categories; see the :mod:`warnings`
.. module for more information.

以下の例外は警告カテゴリとして使われます。詳細については
:mod:`warnings` モジュールを参照してください。


.. 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.

   モジュールインポートの誤りと思われるものに対する警告の基底クラスです。

   .. versionadded:: 2.5


.. exception:: UnicodeWarning

   .. Base class for warnings related to Unicode.

   ユニコードに関連した警告の基底クラスです。

   .. versionadded:: 2.5


例外のクラス階層
-------------------

.. The class hierarchy for built-in exceptions is:

組み込み例外のクラス階層は以下のようになっています:


.. literalinclude:: ../includes/exception_hierarchy.txt

