組み込み例外
************

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

For class exceptions, in a "try" statement with an "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.

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 "raise" statement.
If the exception class is derived from the standard root class
"BaseException", the associated value is present as the exception
instance’s "args" attribute.

ユーザによるコードも組み込み例外を送出できます。これを使って、例外ハン
ドラをテストしたり、インタプリタが同じ例外を送出する状況と 「ちょうど
同じような」 エラー条件であることを報告したりできます。しかし、ユーザ
のコードが適切でないエラーを送出するのを妨げる方法はないので注意してく
ださい。

組み込み例外クラスは新たな例外を定義するためにサブクラス化することがで
きます。新しい例外は、"Exception" クラスかそのサブクラスの一つから派生
することをお勧めします。 "BaseException" からは派生しないで下さい。例
外を定義する上での詳しい情報は、 Python チュートリアルの ユーザー定義
例外 の項目にあります。

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
   "Exception").  If "str()" or "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.

   バージョン 2.5 で追加.

   args

      The tuple of arguments given to the exception constructor.  Some
      built-in exceptions (like "IOError") 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.

exception Exception

   システム終了以外の全ての組み込み例外はこのクラスから派生しています
   。全てのユーザ定義例外もこのクラスから派生させるべきです。

   バージョン 2.5 で変更: Changed to inherit from "BaseException".

exception StandardError

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

exception ArithmeticError

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

exception BufferError

   バッファ に関連する操作が行えなかったときに送出されます。

exception LookupError

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

exception EnvironmentError

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

   バージョン 1.5.2 で追加.

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

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

The following exceptions are the exceptions that are actually raised.

exception AssertionError

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

exception AttributeError

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

exception EOFError

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

exception FloatingPointError

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

exception GeneratorExit

   Raised when a *generator*’s "close()" method is called.  It
   directly inherits from "BaseException" instead of "StandardError"
   since it is technically not an error.

   バージョン 2.5 で追加.

   バージョン 2.6 で変更: Changed to inherit from "BaseException".

exception IOError

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

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

   バージョン 2.6 で変更: Changed "socket.error" to use this as a base
   class.

exception ImportError

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

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, "TypeError" is raised.)

exception KeyError

   マッピング (辞書) のキーが、既存のキーの集合内に見つからなかった場
   合に送出されます。

exception KeyboardInterrupt

   Raised when the user hits the interrupt key (normally "Control-C"
   or "Delete").  During execution, a check for interrupts is made
   regularly. Interrupts typed when a built-in function "input()" or
   "raw_input()" is waiting for input also raise this exception. The
   exception inherits from "BaseException" so as to not be
   accidentally caught by code that catches "Exception" and thus
   prevent the interpreter from exiting.

   バージョン 2.5 で変更: Changed to inherit from "BaseException".

exception MemoryError

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

exception NameError

   ローカルまたはグローバルの名前が見つからなかった場合に送出されます
   。これは非修飾の (訳注: "spam.egg" ではなく単に "egg" のような) 名
   前のみに適用されます。関連値は見つからなかった名前を含むエラーメッ
   セージです。

exception NotImplementedError

   This exception is derived from "RuntimeError".  In user defined
   base classes, abstract methods should raise this exception when
   they require derived classes to override the method.

   バージョン 1.5.2 で追加.

exception OSError

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

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

   バージョン 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 "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.

exception ReferenceError

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

   バージョン 2.2 で追加: Previously known as the
   "weakref.ReferenceError" exception.

exception RuntimeError

   他のカテゴリに分類できないエラーが検出された場合に送出されます。関
   連値は、何が問題だったのかをより詳細に示す文字列です。

exception StopIteration

   Raised by an *iterator*’s "next()" method to signal that there are
   no further values.  This is derived from "Exception" rather than
   "StandardError", since this is not considered an error in its
   normal application.

   バージョン 2.2 で追加.

exception SyntaxError

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

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

exception IndentationError

   正しくないインデントに関する構文エラーの基底クラスです。これは
   "SyntaxError" のサブクラスです。

exception TabError

   タブとスペースを一貫しない方法でインデントに使っているときに送出さ
   れます。これは "IndentationError" のサブクラスです。

exception SystemError

   インタプリタが内部エラーを発見したが、状況は全ての望みを棄てさせる
   ほど深刻ではないと思われる場合に送出されます。関連値は (下位層で)
   どの動作が失敗したかを示す文字列です。

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

exception SystemExit

   This exception is raised by the "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 "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.

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

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

   The exception inherits from "BaseException" instead of
   "StandardError" or "Exception" so that it is not accidentally
   caught by code that catches "Exception".  This allows the exception
   to properly propagate up and cause the interpreter to exit.

   バージョン 2.5 で変更: Changed to inherit from "BaseException".

exception TypeError

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

exception UnboundLocalError

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

   バージョン 2.0 で追加.

exception UnicodeError

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

   "UnicodeError" はエンコードまたはデコードのエラーの説明を属性として
   持っています。例えば、 "err.object[err.start:err.end]" は、無効な入
   力のうちコーデックが処理に失敗した箇所を表します。

   encoding

      エラーを送出したエンコーディングの名前です。

   reason

      そのコーデックエラーを説明する文字列です。

   object

      コーデックがエンコードまたはデコードしようとしたオブジェクトです
      。

   start

      "object" の最初の無効なデータのインデクスです。

   end

      "object" の最後の無効なデータの次のインデクスです。

   バージョン 2.0 で追加.

exception UnicodeEncodeError

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

   バージョン 2.3 で追加.

exception UnicodeDecodeError

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

   バージョン 2.3 で追加.

exception UnicodeTranslateError

   Unicode 関連のエラーが変換中に発生した際に送出されます。
   "UnicodeError" のサブクラスです。

   バージョン 2.3 で追加.

exception ValueError

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

exception VMSError

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

exception WindowsError

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

   バージョン 2.0 で追加.

   バージョン 2.5 で変更: Previous versions put the "GetLastError()"
   codes into "errno".

exception ZeroDivisionError

   除算や剰余演算の第二引数が 0 であった場合に送出されます。関連値は文
   字列で、その演算における被演算子と演算子の型を示します。

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

exception Warning

   警告カテゴリの基底クラスです。

exception UserWarning

   ユーザコードによって生成される警告の基底クラスです。

exception DeprecationWarning

   廃止された機能に対する警告の基底クラスです。

exception PendingDeprecationWarning

   将来廃止される予定の機能に対する警告の基底クラスです。

exception SyntaxWarning

   曖昧な構文に対する警告の基底クラスです。

exception RuntimeWarning

   あいまいなランタイム挙動に対する警告の基底クラスです。

exception FutureWarning

   将来意味構成が変わることになっている文の構成に対する警告の基底クラ
   スです。

exception ImportWarning

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

   バージョン 2.5 で追加.

exception UnicodeWarning

   Unicode に関連した警告の基底クラスです。

   バージョン 2.5 で追加.


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

組み込み例外のクラス階層は以下のとおりです:

   BaseException
    +-- SystemExit
    +-- KeyboardInterrupt
    +-- GeneratorExit
    +-- Exception
         +-- StopIteration
         +-- StandardError
         |    +-- BufferError
         |    +-- ArithmeticError
         |    |    +-- FloatingPointError
         |    |    +-- OverflowError
         |    |    +-- ZeroDivisionError
         |    +-- AssertionError
         |    +-- AttributeError
         |    +-- EnvironmentError
         |    |    +-- IOError
         |    |    +-- OSError
         |    |         +-- WindowsError (Windows)
         |    |         +-- VMSError (VMS)
         |    +-- EOFError
         |    +-- ImportError
         |    +-- LookupError
         |    |    +-- IndexError
         |    |    +-- KeyError
         |    +-- MemoryError
         |    +-- NameError
         |    |    +-- UnboundLocalError
         |    +-- ReferenceError
         |    +-- RuntimeError
         |    |    +-- NotImplementedError
         |    +-- SyntaxError
         |    |    +-- IndentationError
         |    |         +-- TabError
         |    +-- SystemError
         |    +-- TypeError
         |    +-- ValueError
         |         +-- UnicodeError
         |              +-- UnicodeDecodeError
         |              +-- UnicodeEncodeError
         |              +-- UnicodeTranslateError
         +-- Warning
              +-- DeprecationWarning
              +-- PendingDeprecationWarning
              +-- RuntimeWarning
              +-- SyntaxWarning
              +-- UserWarning
              +-- FutureWarning
   	   +-- ImportWarning
   	   +-- UnicodeWarning
   	   +-- BytesWarning
