例外処理
********

The functions described in this chapter will let you handle and raise
Python exceptions.  It is important to understand some of the basics
of Python exception handling.  It works somewhat like the Unix "errno"
variable: there is a global indicator (per thread) of the last error
that occurred.  Most functions don’t clear this on success, but will
set it to indicate the cause of the error on failure.  Most functions
also return an error indicator, usually *NULL* if they are supposed to
return a pointer, or "-1" if they return an integer (exception: the
"PyArg_*()" functions return "1" for success and "0" for failure).

ある関数が呼び出した関数がいくつか失敗したために、その関数が失敗しなけ
ればならないとき、一般的にエラーインジケータを設定しません。呼び出した
関数がすでに設定しています。エラーを処理して例外をクリアするか、あるい
は (オブジェクト参照またはメモリ割り当てのような)それが持つどんなリソ
ースも取り除いた後に戻るかのどちらか一方を行う責任があります。エラーを
処理する準備をしていなければ、普通に続けるべきでは *ありません*。エラ
ーのために戻る場合は、エラーが設定されていると呼び出し元に知らせること
が大切です。エラーが処理されていない場合または丁寧に伝えられている場合
には、Python/C APIのさらなる呼び出しは意図した通りには動かない可能性が
あり、不可解な形で失敗するかもしれません。

The error indicator consists of three Python objects corresponding to
the Python variables "sys.exc_type", "sys.exc_value" and
"sys.exc_traceback". API functions exist to interact with the error
indicator in various ways.  There is a separate error indicator for
each thread.

void PyErr_PrintEx(int set_sys_last_vars)

   "sys.stderr" へ標準トレースバックを出力し、エラーインジケータをクリ
   アします。エラーインジケータが設定されているときにだけ、この関数を
   呼び出してください。(それ以外の場合、致命的なエラーを引き起こすでし
   ょう!)

   *set_sys_last_vars* が非ゼロであれば、 "sys.last_type",
   "sys.last_value", "sys.last_traceback" 変数が、表示される例外のタイ
   プ、値、トレースバックそれぞれに反映されます。

void PyErr_Print()

   "PyErr_PrintEx(1)" のエイリアスです。

PyObject* PyErr_Occurred()
    *Return value: Borrowed reference.*

   エラーインジケータが設定されているかテストします。設定されている場
   合は、例外の *型* ("PyErr_Set*()" 関数の一つあるいは
   "PyErr_Restore()" への最も新しい呼び出しに対する第一引数)を返します
   。設定されていない場合は *NULL* を返します。あなたは戻り値への参照
   を持っていませんので、それに "Py_DECREF()" する必要はありません。

   注釈: 戻り値を特定の例外と比較しないでください。その代わりに、下
     に示す "PyErr_ExceptionMatches()" を使ってください。(比較は簡単に
     失敗す るでしょう。なぜなら、例外はクラスではなくインスタンスかも
     しれな いし、あるいは、クラス例外の場合は期待される例外のサブクラ
     スかも しれないからです。)

int PyErr_ExceptionMatches(PyObject *exc)

   "PyErr_GivenExceptionMatches(PyErr_Occurred(), exc)" と同じ。例外が
   実際に設定されたときにだけ、これを呼び出だすべきです。例外が発生し
   ていないならば、メモリアクセス違反が起きるでしょう。

int PyErr_GivenExceptionMatches(PyObject *given, PyObject *exc)

   Return true if the *given* exception matches the exception in
   *exc*.  If *exc* is a class object, this also returns true when
   *given* is an instance of a subclass.  If *exc* is a tuple, all
   exceptions in the tuple (and recursively in subtuples) are searched
   for a match.

void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb)

   ある状況では、以下の "PyErr_Fetch()" が返す値は 「正規化されていな
   い」 可能性があります。つまり、 "*exc" はクラスオブジェクトだが
   "*val" は同じクラスのインスタンスではないという意味です。この関数は
   そのような場合にそのクラスをインスタンス化するために使われます。そ
   の値がすでに正規化されている場合は何も起きません。遅延正規化はパフ
   ォーマンスを改善するために実装されています。

void PyErr_Clear()

   エラーインジケータをクリアします。エラーインジケータが設定されてい
   ないならば、効果はありません。

void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)

   エラーインジケータをアドレスを渡す三つの変数の中へ取り出します。エ
   ラーインジケータが設定されていない場合は、三つすべての変数を *NULL*
   に設定します。エラーインジケータが設定されている場合はクリアされ、
   あなたは取り出されたそれぞれのオブジェクトへの参照を持つことになり
   ます。型オブジェクトが *NULL* でないときでさえ、その値とトレースバ
   ックオブジェクトは *NULL* かもしれません。

   注釈: This function is normally only used by code that needs to
     handle exceptions or by code that needs to save and restore the
     error indicator temporarily.

void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)

   三つのオブジェクトからエラーインジケータを設定します。エラーインジ
   ケータがすでに設定されている場合は、最初にクリアされます。オブジェ
   クトが *NULL* ならば、エラーインジケータがクリアされます。*NULL* の
   typeと非 *NULL* のvalueあるいは tracebackを渡してはいけません。例外
   の型(type)はクラスであるべきです。無効な例外の型(type)あるいは値
   (value)を渡してはいけません。(これらの規則を破ると後で気付きにくい
   問題の原因となるでしょう。) この呼び出しはそれぞれのオブジェクトへ
   の参照を取り除きます: あなたは呼び出しの前にそれぞれのオブジェクト
   への参照を持たなければならないのであり、また呼び出しの後にはもはや
   これらの参照を持っていません。(これを理解していない場合は、この関数
   を使ってはいけません。注意しておきます。)

   注釈: This function is normally only used by code that needs to
     save and restore the error indicator temporarily; use
     "PyErr_Fetch()" to save the current exception state.

void PyErr_SetString(PyObject *type, const char *message)

   This is the most common way to set the error indicator.  The first
   argument specifies the exception type; it is normally one of the
   standard exceptions, e.g. "PyExc_RuntimeError".  You need not
   increment its reference count. The second argument is an error
   message; it is converted to a string object.

void PyErr_SetObject(PyObject *type, PyObject *value)

   この関数は "PyErr_SetString()" に似ていますが、例外の 「値(value)」
   として任意のPythonオブジェクトを指定することができます。

PyObject* PyErr_Format(PyObject *exception, const char *format, ...)
    *Return value: Always NULL.*

   This function sets the error indicator and returns *NULL*.
   *exception* should be a Python exception class.  The *format* and
   subsequent parameters help format the error message; they have the
   same meaning and values as in "PyString_FromFormat()".

void PyErr_SetNone(PyObject *type)

   これは "PyErr_SetObject(type, Py_None)" を省略したものです。

int PyErr_BadArgument()

   これは "PyErr_SetString(PyExc_TypeError, message)" を省略したもので
   、ここで *message* は組み込み操作が不正な引数で呼び出されたというこ
   とを表しています。主に内部で使用するためのものです。

PyObject* PyErr_NoMemory()
    *Return value: Always NULL.*

   これは "PyErr_SetNone(PyExc_MemoryError)" を省略したもので、*NULL*
   を返します。したがって、メモリ不足になったとき、オブジェクト割り当
   て関数は "return PyErr_NoMemory();" と書くことができます。

PyObject* PyErr_SetFromErrno(PyObject *type)
    *Return value: Always NULL.*

   Cライブラリ関数がエラーを返してC変数 "errno" を設定したときに、これ
   は例外を発生させるために便利な関数です。第一要素が整数 "errno" 値で
   、第二要素が ("strerror()" から得られる)対応するエラーメッセージで
   あるタプルオブジェクトを構成します。それから、
   "PyErr_SetObject(type, object)" を呼び出します。 Unixでは、 "errno"
   値が "EINTR" であるとき、すなわち割り込まれたシステムコールを表して
   いるとき、これは "PyErr_CheckSignals()" を呼び出し、それがエラーイ
   ンジケータを設定した場合は設定されたままにしておきます。関数は常に
   *NULL* を返します。したがって、システムコールがエラーを返したとき、
   システムコールのラッパー関数は "return PyErr_SetFromErrno(type);"
   と書くことができます。

PyObject* PyErr_SetFromErrnoWithFilenameObject(PyObject *type, PyObject *filenameObject)

   Similar to "PyErr_SetFromErrno()", with the additional behavior
   that if *filenameObject* is not *NULL*, it is passed to the
   constructor of *type* as a third parameter.  In the case of
   exceptions such as "IOError" and "OSError", this is used to define
   the "filename" attribute of the exception instance.

PyObject* PyErr_SetFromErrnoWithFilename(PyObject *type, const char *filename)
    *Return value: Always NULL.*

   Similar to "PyErr_SetFromErrnoWithFilenameObject()", but the
   filename is given as a C string.

PyObject* PyErr_SetFromWindowsErr(int ierr)
    *Return value: Always NULL.*

   これは "WindowsError" を発生させるために便利な関数です。 "0" の
   *ierr* とともに呼び出された場合、 "GetLastError()" が返すエラーコー
   ドが代りに使われます。 *ierr* あるいは "GetLastError()" によって与
   えられるエラーコードのWindows用の説明を取り出すために、Win32関数
   "FormatMessage()" を呼び出します。それから、第一要素が *ierr* 値で
   第二要素が("FormatMessage()" から得られる) 対応するエラーメッセージ
   であるタプルオブジェクトを構成します。そして、
   "PyErr_SetObject(PyExc_WindowsError, object)" を呼び出します。この
   関数は常に *NULL* を返します。利用可能範囲: Windows。

PyObject* PyErr_SetExcFromWindowsErr(PyObject *type, int ierr)
    *Return value: Always NULL.*

   "PyErr_SetFromWindowsErr()" に似ていますが、送出する例外の型を指定
   する引数が追加されています。利用可能範囲: Windows。

   バージョン 2.3 で追加.

PyObject* PyErr_SetFromWindowsErrWithFilenameObject(int ierr, PyObject *filenameObject)

   Similar to "PyErr_SetFromWindowsErr()", with the additional
   behavior that if *filenameObject* is not *NULL*, it is passed to
   the constructor of "WindowsError" as a third parameter.
   Availability: Windows.

PyObject* PyErr_SetFromWindowsErrWithFilename(int ierr, const char *filename)
    *Return value: Always NULL.*

   Similar to "PyErr_SetFromWindowsErrWithFilenameObject()", but the
   filename is given as a C string. Availability: Windows.

PyObject* PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *type, int ierr, PyObject *filename)

   "PyErr_SetFromWindowsErrWithFilenameObject()" に似ていますが、送出
   する例外の型を指定する引数が追加されています。利用可能範囲: Windows
   。

   バージョン 2.3 で追加.

PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject *type, int ierr, const char *filename)
    *Return value: Always NULL.*

   "PyErr_SetFromWindowsErrWithFilename()" に似ていますが、送出する例
   外の型を指定する引数が追加されています。利用可能範囲: Windows。

   バージョン 2.3 で追加.

void PyErr_BadInternalCall()

   "PyErr_SetString(PyExc_SystemError, message)" を省略したものです。
   ここで *message* は内部操作(例えば、Python/C API関数)が不正な引数と
   ともに呼び出されたということを示しています。主に内部で使用するため
   のものです。

int PyErr_WarnEx(PyObject *category, char *message, int stacklevel)

   Issue a warning message.  The *category* argument is a warning
   category (see below) or *NULL*; the *message* argument is a message
   string.  *stacklevel* is a positive number giving a number of stack
   frames; the warning will be issued from the  currently executing
   line of code in that stack frame.  A *stacklevel* of 1 is the
   function calling "PyErr_WarnEx()", 2 is  the function above that,
   and so forth.

   This function normally prints a warning message to *sys.stderr*;
   however, it is also possible that the user has specified that
   warnings are to be turned into errors, and in that case this will
   raise an exception.  It is also possible that the function raises
   an exception because of a problem with the warning machinery (the
   implementation imports the "warnings" module to do the heavy
   lifting). The return value is "0" if no exception is raised, or
   "-1" if an exception is raised.  (It is not possible to determine
   whether a warning message is actually printed, nor what the reason
   is for the exception; this is intentional.)  If an exception is
   raised, the caller should do its normal exception handling (for
   example, "Py_DECREF()" owned references and return an error value).

   Warning categories must be subclasses of "PyExc_Warning";
   "PyExc_Warning" is a subclass of "PyExc_Exception"; the default
   warning category is "PyExc_RuntimeWarning". The standard Python
   warning categories are available as global variables whose names
   are enumerated at Standard Warning Categories.

   警告をコントロールするための情報については、 "warnings" モジュール
   のドキュメンテーションとコマンドライン・ドキュメンテーションの "-W"
   オプションを参照してください。警告コントロールのためのC APIはありま
   せん。

int PyErr_Warn(PyObject *category, char *message)

   Issue a warning message.  The *category* argument is a warning
   category (see below) or *NULL*; the *message* argument is a message
   string.  The warning will appear to be issued from the function
   calling "PyErr_Warn()", equivalent to calling "PyErr_WarnEx()" with
   a *stacklevel* of 1.

   Deprecated; use "PyErr_WarnEx()" instead.

int PyErr_WarnExplicit(PyObject *category, const char *message, const char *filename, int lineno, const char *module, PyObject *registry)

   すべての警告の属性を明示的に制御した警告メッセージを出します。これ
   は Python 関数 "warnings.warn_explicit()" の直接的なラッパで、さら
   に情報を得るにはそちらを参照してください。そこに説明されているデフ
   ォルトの効果を得るために、 *module* と *registry* 引数は *NULL* に
   設定することができます。

int PyErr_WarnPy3k(char *message, int stacklevel)

   Issue a "DeprecationWarning" with the given *message* and
   *stacklevel* if the "Py_Py3kWarningFlag" flag is enabled.

   バージョン 2.6 で追加.

int PyErr_CheckSignals()

   この関数はPythonのシグナル処理とやりとりすることができます。シグナ
   ルがそのプロセスへ送られたかどうかチェックし、そうならば対応するシ
   グナルハンドラを呼び出します。 "signal" モジュールがサポートされて
   いる場合は、これはPythonで書かれたシグナルハンドラを呼び出せます。
   すべての場合で、 "SIGINT" のデフォルトの効果は "KeyboardInterrupt"
   例外を発生させることです。例外が発生した場合、エラーインジケータが
   設定され、関数は "-1" を返します。そうでなければ、関数は "0" を返し
   ます。エラーインジケータが以前に設定されている場合は、それがクリア
   されるかどうかわからない。

void PyErr_SetInterrupt()

   この関数は廃止されています。 "SIGINT" シグナルが到達した影響をシミ
   ュレートします — 次に "PyErr_CheckSignals()" が呼ばれるとき、
   "KeyboardInterrupt" は送出されるでしょう。インタプリタロックを保持
   することなく呼び出すことができます。

int PySignal_SetWakeupFd(int fd)

   This utility function specifies a file descriptor to which a "'\0'"
   byte will be written whenever a signal is received.  It returns the
   previous such file descriptor.  The value "-1" disables the
   feature; this is the initial state. This is equivalent to
   "signal.set_wakeup_fd()" in Python, but without any error checking.
   *fd* should be a valid file descriptor.  The function should only
   be called from the main thread.

   バージョン 2.6 で追加.

PyObject* PyErr_NewException(char *name, PyObject *base, PyObject *dict)
    *Return value: New reference.*

   このユーティリティ関数は新しい例外クラスを作成して返します。 *name*
   引数は新しい例外の名前、 "module.classname" 形式の C文字列でなけれ
   ばならない。 *base* と *dict* 引数は通常 *NULL* です。これはすべて
   の例外のためのルート、組み込み名 "Exception" (Cでは
   "PyExc_Exception" としてアクセス可能)をルートとして派生したクラスオ
   ブジェクトを作成します。

   新しいクラスの "__module__" 属性は *name* 引数の前半部分(最後のドッ
   トまで)に設定され、クラス名は後半部分(最後のドットの後)に設定されま
   す。 *base* 引数は代わりのベースクラスを指定するために使えます; 一
   つのクラスでも、クラスのタプルでも構いません。 *dict* 引数はクラス
   変数とメソッドの辞書を指定するために使えます。

PyObject* PyErr_NewExceptionWithDoc(char *name, char *doc, PyObject *base, PyObject *dict)
    *Return value: New reference.*

   "PyErr_NewException()" とほぼ同じですが、新しい例外クラスに簡単に
   docstring を設定できます。 *doc* が *NULL* で無い場合、それが例外ク
   ラスの docstring になります。

   バージョン 2.7 で追加.

void PyErr_WriteUnraisable(PyObject *obj)

   例外が設定されているがインタプリタが実際に例外を発生させることがで
   きないときに、このユーティリティ関数は警告メッセージを "sys.stderr"
   へ出力します。例えば、例外が "__del__()" メソッドで発生したときに使
   われます。

   発生させられない例外が起きたコンテキストを指し示す単一の引数 *obj*
   で関数が呼び出されます。 可能な場合は、 *obj* の repr 文字列が警告
   メッセージに出力されます。


Unicode 例外オブジェクト
========================

以下の関数は C言語から Unicode 例外を作ったり修正したりするために利用
します。

PyObject* PyUnicodeDecodeError_Create(const char *encoding, const char *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason)

   Create a "UnicodeDecodeError" object with the attributes
   *encoding*, *object*, *length*, *start*, *end* and *reason*.

PyObject* PyUnicodeEncodeError_Create(const char *encoding, const Py_UNICODE *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason)

   Create a "UnicodeEncodeError" object with the attributes
   *encoding*, *object*, *length*, *start*, *end* and *reason*.

PyObject* PyUnicodeTranslateError_Create(const Py_UNICODE *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason)

   Create a "UnicodeTranslateError" object with the attributes
   *object*, *length*, *start*, *end* and *reason*.

PyObject* PyUnicodeDecodeError_GetEncoding(PyObject *exc)
PyObject* PyUnicodeEncodeError_GetEncoding(PyObject *exc)

   与えられた例外オブジェクトの *encoding* 属性を返します。

PyObject* PyUnicodeDecodeError_GetObject(PyObject *exc)
PyObject* PyUnicodeEncodeError_GetObject(PyObject *exc)
PyObject* PyUnicodeTranslateError_GetObject(PyObject *exc)

   与えられた例外オブジェクトの *object* 属性を返します。

int PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start)
int PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start)
int PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start)

   渡された例外オブジェクトから *start* 属性を取得して **start* に格納
   します。*start* は *NULL* であってはなりません。成功したら "0" を、
   失敗したら "-1" を返します。

int PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start)
int PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start)
int PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start)

   渡された例外オブジェクトの *start* 属性を *start* に設定します。成
   功したら "0" を、失敗したら "-1" を返します。

int PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
int PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
int PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *end)

   渡された例外オブジェクトから *end* 属性を取得して **end* に格納しま
   す。*end* は *NULL* であってはなりません。成功したら "0" を、失敗し
   たら "-1" を返します。

int PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end)
int PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end)
int PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end)

   渡された例外オブジェクトの *end* 属性を *end* に設定します。成功し
   たら "0" を、失敗したら "-1" を返します。

PyObject* PyUnicodeDecodeError_GetReason(PyObject *exc)
PyObject* PyUnicodeEncodeError_GetReason(PyObject *exc)
PyObject* PyUnicodeTranslateError_GetReason(PyObject *exc)

   渡された例外オブジェクトの *reason* 属性を返します。

int PyUnicodeDecodeError_SetReason(PyObject *exc, const char *reason)
int PyUnicodeEncodeError_SetReason(PyObject *exc, const char *reason)
int PyUnicodeTranslateError_SetReason(PyObject *exc, const char *reason)

   渡された例外オブジェクトの *reason* 属性を *reason* に設定します。
   成功したら "0" を、失敗したら "-1" を返します。


再帰の管理
==========

これら2つの関数は C レベルの再帰呼び出しを安全に実行する方法を、コアモ
ジュールにも拡張モジュールにも提供します。再帰を使ったコードが必ずしも
Python コードを実行するわけではない場合 (Python コードは再帰の深さを自
動的に追跡します)、これらの関数が必要となります。

int Py_EnterRecursiveCall(const char *where)

   C レベルの再帰呼び出しをしようとしているところに印を付けます。

   "USE_STACKCHECK" が定義されている場合、 OS のスタックがオーバーフロ
   ーがしたかどうかを "PyOS_CheckStack()" を使ってチェックします。もし
   オーバーフローしているなら、 "MemoryError" をセットしゼロでない値を
   返します。

   The function then checks if the recursion limit is reached.  If
   this is the case, a "RuntimeError" is set and a nonzero value is
   returned. Otherwise, zero is returned.

   *where* should be a string such as "" in instance check"" to be
   concatenated to the "RuntimeError" message caused by the recursion
   depth limit.

void Py_LeaveRecursiveCall()

   "Py_EnterRecursiveCall()" を終了させます。
   "Py_EnterRecursiveCall()" の *成功した* 呼び出しに対し 1 回呼ばなけ
   ればなりません。


標準例外
========

"PyExc_" の後ろにPythonの例外名が続く名前をもつグローバル変数として、
すべての標準Python例外が利用可能です。これらは型 "PyObject*" を持ち、
すべてクラスオブジェクトです。完璧を期するために、すべての変数を以下に
列挙します:

+-------------------------------------------+-----------------------------------+------------+
| C名                                       | Python名                          | 注釈       |
+===========================================+===================================+============+
| "PyExc_BaseException"                     | "BaseException"                   | (1), (4)   |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_Exception"                         | "Exception"                       | (1)        |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_StandardError"                     | "StandardError"                   | (1)        |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_ArithmeticError"                   | "ArithmeticError"                 | (1)        |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_AssertionError"                    | "AssertionError"                  |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_AttributeError"                    | "AttributeError"                  |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_BufferError"                       | "BufferError"                     |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_EnvironmentError"                  | "EnvironmentError"                | (1)        |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_EOFError"                          | "EOFError"                        |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_FloatingPointError"                | "FloatingPointError"              |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_GeneratorExit"                     | "GeneratorExit"                   |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_ImportError"                       | "ImportError"                     |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_IndentationError"                  | "IndentationError"                |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_IndexError"                        | "IndexError"                      |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_IOError"                           | "IOError"                         |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_KeyError"                          | "KeyError"                        |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_KeyboardInterrupt"                 | "KeyboardInterrupt"               |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_LookupError"                       | "LookupError"                     | (1)        |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_MemoryError"                       | "MemoryError"                     |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_NameError"                         | "NameError"                       |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_NotImplementedError"               | "NotImplementedError"             |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_OSError"                           | "OSError"                         |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_OverflowError"                     | "OverflowError"                   |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_ReferenceError"                    | "ReferenceError"                  | (2)        |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_RuntimeError"                      | "RuntimeError"                    |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_StopIteration"                     | "StopIteration"                   |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_SyntaxError"                       | "SyntaxError"                     |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_SystemError"                       | "SystemError"                     |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_SystemExit"                        | "SystemExit"                      |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_TabError"                          | "TabError"                        |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_TypeError"                         | "TypeError"                       |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_UnboundLocalError"                 | "UnboundLocalError"               |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_UnicodeDecodeError"                | "UnicodeDecodeError"              |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_UnicodeEncodeError"                | "UnicodeEncodeError"              |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_UnicodeError"                      | "UnicodeError"                    |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_UnicodeTranslateError"             | "UnicodeTranslateError"           |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_VMSError"                          | "VMSError"                        | (5)        |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_ValueError"                        | "ValueError"                      |            |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_WindowsError"                      | "WindowsError"                    | (3)        |
+-------------------------------------------+-----------------------------------+------------+
| "PyExc_ZeroDivisionError"                 | "ZeroDivisionError"               |            |
+-------------------------------------------+-----------------------------------+------------+

注釈:

1. これは別の標準例外のためのベースクラスです。

2. これは "weakref.ReferenceError" と同じです。

3. Windowsでのみ定義されています。プリプロセッサマクロ "MS_WINDOWS"
   が 定義されているかテストすることで、これを使うコードを保護してくだ
   さ い。

4. バージョン 2.5 で追加.

5. Only defined on VMS; protect code that uses this by testing that
   the preprocessor macro "__VMS" is defined.


Standard Warning Categories
===========================

All standard Python warning categories are available as global
variables whose names are "PyExc_" followed by the Python exception
name. These have the type "PyObject*"; they are all class objects. For
completeness, here are all the variables:

+--------------------------------------------+-----------------------------------+------------+
| C名                                        | Python名                          | 注釈       |
+============================================+===================================+============+
| "PyExc_Warning"                            | "Warning"                         | (1)        |
+--------------------------------------------+-----------------------------------+------------+
| "PyExc_BytesWarning"                       | "BytesWarning"                    |            |
+--------------------------------------------+-----------------------------------+------------+
| "PyExc_DeprecationWarning"                 | "DeprecationWarning"              |            |
+--------------------------------------------+-----------------------------------+------------+
| "PyExc_FutureWarning"                      | "FutureWarning"                   |            |
+--------------------------------------------+-----------------------------------+------------+
| "PyExc_ImportWarning"                      | "ImportWarning"                   |            |
+--------------------------------------------+-----------------------------------+------------+
| "PyExc_PendingDeprecationWarning"          | "PendingDeprecationWarning"       |            |
+--------------------------------------------+-----------------------------------+------------+
| "PyExc_RuntimeWarning"                     | "RuntimeWarning"                  |            |
+--------------------------------------------+-----------------------------------+------------+
| "PyExc_SyntaxWarning"                      | "SyntaxWarning"                   |            |
+--------------------------------------------+-----------------------------------+------------+
| "PyExc_UnicodeWarning"                     | "UnicodeWarning"                  |            |
+--------------------------------------------+-----------------------------------+------------+
| "PyExc_UserWarning"                        | "UserWarning"                     |            |
+--------------------------------------------+-----------------------------------+------------+

注釈:

1. This is a base class for other standard warning categories.


String Exceptions
=================

バージョン 2.6 で変更: All exceptions to be raised or caught must be
derived from "BaseException". Trying to raise a string exception now
raises "TypeError".
