예외 처리

이 장에서 설명하는 함수를 사용하면 파이썬 예외를 처리하고 발생시킬 수 있습니다. 파이썬 예외 처리의 기본 사항을 이해하는 것이 중요합니다. POSIX errno 변수와 비슷하게 작동합니다: 발생한 마지막 에러에 대한 전역 표시기(스레드 당)가 있습니다. 대부분 C API 함수는 성공 시 이를 지우지 않지만, 실패 시 에러의 원인을 나타내도록 설정합니다. 대부분 C API 함수는 에러 표시기도 반환합니다, 일반적으로 포인터를 반환해야 하면 NULL, 정수를 반환하면 -1을 반환합니다 (예외: PyArg_* 함수는 성공하면 1을, 실패하면 0을 반환합니다).

구체적으로, 에러 표시기는 세 가지 객체 포인터로 구성됩니다: 예외 형, 예외 값 및 트레이스백 객체. 이러한 포인터들은 설정되지 않으면 NULL이 될 수 있습니다 (하지만 일부 조합은 금지되어 있습니다, 예를 들어 예외 형이 NULL이면 NULL이 아닌 트레이스백을 가질 수 없습니다).

호출한 일부 함수가 실패하여 함수가 실패해야 할 때, 일반적으로 에러 표시기를 설정하지 않습니다; 호출된 함수가 이미 설정했습니다. 에러를 처리하고 예외를 지우거나 보유한 모든 리소스(가령 객체 참조나 메모리 할당)를 정리한 후 반환해야 할 책임이 있습니다; 에러를 처리할 준비가 되지 않았을 때 정상적으로 계속되지 않아야 합니다. 에러로 인해 반환하면, 호출자에게 에러가 설정되었음을 알리는 것이 중요합니다. 에러를 처리하지 않거나 신중하게 전파하지 않으면, 파이썬/C API에 대한 추가 호출이 의도한 대로 작동하지 않을 수 있으며 알 수 없는 방식으로 실패할 수 있습니다.

참고

에러 표시기는 sys.exc_info()의 결과가 아닙니다. 전자는 아직 포착되지 않은 (따라서 여전히 전파 중인) 예외에 해당하는 반면, 후자는 포착된 후 (따라서 전파가 중단된) 예외를 반환합니다.

인쇄와 지우기

void PyErr_Clear()
Part of the 안정 ABI.

에러 표시기를 지웁니다. 에러 표시기가 설정되어 있지 않으면 효과가 없습니다.

void PyErr_PrintEx(int set_sys_last_vars)
Part of the 안정 ABI.

표준 트레이스백을 sys.stderr로 인쇄하고 에러 표시기를 지웁니다. 에러가 SystemExit아닌 한, 이 경우에는 트레이스백이 인쇄되지 않고 파이썬 프로세스는 SystemExit 인스턴스에 의해 지정된 에러 코드로 종료됩니다.

에러 표시기가 설정된 경우**에만** 이 함수를 호출하십시오. 그렇지 않으면 치명적인 에러가 발생합니다!

set_sys_last_vars가 0이 아니면, 변수 sys.last_exc 는 인쇄되는 예외로 설정됩니다. 하위 호환성을 위해, 폐지된 변수 sys.last_type, sys.last_valuesys.last_traceback 도 각각 이 예외의 형, 값 및 트레이스백으로 설정됩니다.

버전 3.12에서 변경: The setting of sys.last_exc was added.

void PyErr_Print()
Part of the 안정 ABI.

PyErr_PrintEx(1)의 별칭.

void PyErr_WriteUnraisable(PyObject *obj)
Part of the 안정 ABI.

현재 예외와 obj 인자를 사용하여 sys.unraisablehook() 을 호출합니다.

이 유틸리티 함수는 예외가 설정되었지만, 인터프리터가 실제로 예외를 발생시킬 수 없을 때 sys.stderr에 경고 메시지를 인쇄합니다. 예를 들어, __del__() 메서드에서 예외가 발생할 때 사용됩니다.

이 함수는 발생시킬 수 없는 예외가 발생한 문맥을 식별하는 단일 인자 obj로 호출됩니다. 가능하면, obj의 repr이 경고 메시지에 인쇄됩니다. objNULL이면, 트래이스백만 인쇄됩니다.

이 함수를 호출할 때 예외를 설정되어 있어야 합니다.

버전 3.4에서 변경: Print a traceback. Print only traceback if obj is NULL.

버전 3.8에서 변경: Use sys.unraisablehook().

void PyErr_FormatUnraisable(const char *format, ...)

Similar to PyErr_WriteUnraisable(), but the format and subsequent parameters help format the warning message; they have the same meaning and values as in PyUnicode_FromFormat(). PyErr_WriteUnraisable(obj) is roughly equivalent to PyErr_FormatUnraisable("Exception ignored in: %R", obj). If format is NULL, only the traceback is printed.

Added in version 3.13.

void PyErr_DisplayException(PyObject *exc)
Part of the 안정 ABI 버전 3.12 이후로.

Print the standard traceback display of exc to sys.stderr, including chained exceptions and notes.

Added in version 3.12.

예외 발생시키기

이 함수들은 현재 스레드의 에러 표시기를 설정하는 데 도움이 됩니다. 편의를 위해, 이러한 함수 중 일부는 항상 return 문에서 사용할 NULL 포인터를 반환합니다.

void PyErr_SetString(PyObject *type, const char *message)
Part of the 안정 ABI.

이것은 에러 표시기를 설정하는 가장 일반적인 방법입니다. 첫 번째 인자는 예외 형을 지정합니다; 일반적으로 표준 예외 중 하나입니다, 예를 들어 PyExc_RuntimeError. 새로운 강한 참조를 만들 필요가 없습니다 (예를 들어, Py_INCREF()로). 두 번째 인자는 에러 메시지입니다; 'utf-8' 에서 디코딩됩니다.

void PyErr_SetObject(PyObject *type, PyObject *value)
Part of the 안정 ABI.

이 함수는 PyErr_SetString()과 유사하지만, 예외의 “값”에 대해 임의의 파이썬 객체를 지정할 수 있습니다.

PyObject *PyErr_Format(PyObject *exception, const char *format, ...)
반환값: 항상 NULL. Part of the 안정 ABI.

이 함수는 에러 표시기를 설정하고 NULL을 반환합니다. exception은 파이썬 예외 클래스여야 합니다. format과 후속 매개 변수는 에러 메시지를 포맷하는 데 도움이 됩니다; PyUnicode_FromFormat()에서와 같은 의미와 값을 갖습니다. format은 ASCII 인코딩된 문자열입니다.

PyObject *PyErr_FormatV(PyObject *exception, const char *format, va_list vargs)
반환값: 항상 NULL. Part of the 안정 ABI 버전 3.5 이후로.

PyErr_Format()과 같지만, 가변 개수의 인자 대신 va_list 인자를 취합니다.

Added in version 3.5.

void PyErr_SetNone(PyObject *type)
Part of the 안정 ABI.

이것은 PyErr_SetObject(type, Py_None)의 줄임 표현입니다.

int PyErr_BadArgument()
Part of the 안정 ABI.

이것은 PyErr_SetString(PyExc_TypeError, message)의 줄임 표현입니다, 여기서 message는 잘못된 인자로 내장 연산이 호출되었음을 나타냅니다. 대부분 내부 용입니다.

PyObject *PyErr_NoMemory()
반환값: 항상 NULL. Part of the 안정 ABI.

이것은 PyErr_SetNone(PyExc_MemoryError)의 줄임 표현입니다; NULL을 반환해서 객체 할당 함수는 메모리가 부족할 때 return PyErr_NoMemory(); 라고 쓸 수 있습니다.

PyObject *PyErr_SetFromErrno(PyObject *type)
반환값: 항상 NULL. Part of the 안정 ABI.

C 라이브러리 함수가 에러를 반환하고 C 변수 errno를 설정했을 때 예외를 발생시키는 편의 함수입니다. 첫 번째 항목이 정수 errno 값이고 두 번째 항목이 (strerror()에서 얻은) 해당 에러 메시지인 튜플 객체를 만든 다음, PyErr_SetObject(type, object)를 호출합니다. 유닉스에서, errno 값이 시스템 호출이 중단되었음을 나타내는 EINTR이면, PyErr_CheckSignals()를 호출하고 이것이 에러 표시기를 설정하면, 설정된 그대로 둡니다. 이 함수는 항상 NULL을 반환해서, 시스템 호출에 대한 래퍼 함수는 시스템 호출이 에러를 반환할 때 return PyErr_SetFromErrno(type); 이라고 쓸 수 있습니다.

PyObject *PyErr_SetFromErrnoWithFilenameObject(PyObject *type, PyObject *filenameObject)
반환값: 항상 NULL. Part of the 안정 ABI.

PyErr_SetFromErrno()와 유사하지만, filenameObjectNULL이 아니면, type의 생성자에 세 번째 매개 변수로 전달된다는 추가 동작이 있습니다. OSError 예외의 경우, 예외 인스턴스의 filename 어트리뷰트를 정의하는 데 사용됩니다.

PyObject *PyErr_SetFromErrnoWithFilenameObjects(PyObject *type, PyObject *filenameObject, PyObject *filenameObject2)
반환값: 항상 NULL. Part of the 안정 ABI 버전 3.7 이후로.

PyErr_SetFromErrnoWithFilenameObject()와 유사하지만, 두 개의 파일명을 취하는 함수가 실패할 때 에러를 발생시키기 위해 두 번째 파일명 객체를 취합니다.

Added in version 3.4.

PyObject *PyErr_SetFromErrnoWithFilename(PyObject *type, const char *filename)
반환값: 항상 NULL. Part of the 안정 ABI.

PyErr_SetFromErrnoWithFilenameObject()와 유사하지만, 파일명이 C 문자열로 제공됩니다. filename파일시스템 인코딩과 에러 처리기로 디코딩됩니다.

PyObject *PyErr_SetFromWindowsErr(int ierr)
반환값: 항상 NULL. Part of the 안정 ABI on Windows 버전 3.7 이후로.

OSError를 발생시키는 편의 함수입니다. 0ierr로 호출하면, GetLastError() 호출에서 반환된 에러 코드가 대신 사용됩니다. Win32 함수 FormatMessage()를 호출하여 ierr이나 GetLastError()가 제공하는 에러 코드의 윈도우 설명을 얻은 다음, winerror 어트리뷰트가 에러 코드로 설정되고, strerror 어트리뷰트가 (FormatMessage()에서 얻은) 해당 에러 메시지로 설정된 OSError 객체를 생성한 다음, PyErr_SetObject(PyExc_OSError, object)를 호출합니다. 이 함수는 항상 NULL을 반환합니다.

가용성: Windows.

PyObject *PyErr_SetExcFromWindowsErr(PyObject *type, int ierr)
반환값: 항상 NULL. Part of the 안정 ABI on Windows 버전 3.7 이후로.

PyErr_SetFromWindowsErr() 와 유사하며, 발생시킬 예외 형을 지정하는 추가 매개 변수가 있습니다.

가용성: Windows.

PyObject *PyErr_SetFromWindowsErrWithFilename(int ierr, const char *filename)
반환값: 항상 NULL. Part of the 안정 ABI on Windows 버전 3.7 이후로.

PyErr_SetFromWindowsErr()과 유사하지만, filenameNULL이 아니면, 파일 시스템 인코딩으로 디코딩되고 (os.fsdecode()) OSError의 생성자에 세 번째 매개 변수로 전달되어 예외 인스턴스의 filename 어트리뷰트를 정의하는 데 사용되도록 하는 추가 동작이 있습니다.

가용성: Windows.

PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *type, int ierr, PyObject *filename)
반환값: 항상 NULL. Part of the 안정 ABI on Windows 버전 3.7 이후로.

PyErr_SetExcFromWindowsErr()과 유사하지만, filenameNULL이 아니면, OSError의 생성자에 세 번째 매개 변수로 전달되어 예외 인스턴스의 filename 어트리뷰트를 정의하는 데 사용되도록 하는 추가 동작이 있습니다.

가용성: Windows.

PyObject *PyErr_SetExcFromWindowsErrWithFilenameObjects(PyObject *type, int ierr, PyObject *filename, PyObject *filename2)
반환값: 항상 NULL. Part of the 안정 ABI on Windows 버전 3.7 이후로.

PyErr_SetExcFromWindowsErrWithFilenameObject()와 유사하지만, 두 번째 파일명 객체를 받아들입니다.

가용성: Windows.

Added in version 3.4.

PyObject *PyErr_SetExcFromWindowsErrWithFilename(PyObject *type, int ierr, const char *filename)
반환값: 항상 NULL. Part of the 안정 ABI on Windows 버전 3.7 이후로.

PyErr_SetFromWindowsErrWithFilename()와 유사하며, 발생시킬 예외 형을 지정하는 추가 매개 변수가 있습니다.

가용성: Windows.

PyObject *PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path)
반환값: 항상 NULL. Part of the 안정 ABI 버전 3.7 이후로.

ImportError를 발생시키는 편의 함수입니다. msg는 예외의 메시지 문자열로 설정됩니다. 둘 다 NULL이 될 수 있는, namepath는 각각 ImportErrornamepath 어트리뷰트로 설정됩니다.

Added in version 3.3.

PyObject *PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg, PyObject *name, PyObject *path)
반환값: 항상 NULL. Part of the 안정 ABI 버전 3.6 이후로.

PyErr_SetImportError() 와 매우 비슷하지만, 이 함수는 발생시킬 ImportError의 서브 클래스를 지정할 수 있습니다.

Added in version 3.6.

void PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset)

현재 예외에 대한 파일(file), 줄(line) 및 오프셋(offset) 정보를 설정합니다. 현재 예외가 SyntaxError가 아니면, 추가 어트리뷰트를 설정하여, 예외 인쇄 하위 시스템이 예외가 SyntaxError라고 생각하게 합니다.

Added in version 3.4.

void PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
Part of the 안정 ABI 버전 3.7 이후로.

PyErr_SyntaxLocationObject() 와 비슷하지만, filename파일시스템 인코딩과 에러 처리기로 디코딩되는 바이트 문자열입니다.

Added in version 3.2.

void PyErr_SyntaxLocation(const char *filename, int lineno)
Part of the 안정 ABI.

PyErr_SyntaxLocationEx() 와 비슷하지만, col_offset 매개 변수는 생략됩니다.

void PyErr_BadInternalCall()
Part of the 안정 ABI.

이것은 PyErr_SetString(PyExc_SystemError, message)의 줄임 표현입니다. 여기서 message는 내부 연산(예를 들어 파이썬/C API 함수)이 잘못된 인자로 호출되었음을 나타냅니다. 대부분 내부 용입니다.

경고 발행하기

이 함수를 사용하여 C 코드에서 경고를 발행하십시오. 파이썬 warnings 모듈에서 내보낸 유사한 함수를 미러링합니다. 일반적으로 sys.stderr에 경고 메시지를 인쇄합니다; 그러나, 사용자가 경고를 에러로 전환하도록 지정했을 수도 있으며, 이 경우 예외가 발생합니다. 경고 장치의 문제로 인해 이 함수가 예외를 발생시키는 것도 가능합니다. 예외가 발생하지 않으면 반환 값은 0이고, 예외가 발생하면 -1입니다. (경고 메시지가 실제로 인쇄되는지나 예외의 이유를 확인할 수 없습니다; 이것은 의도적입니다.) 예외가 발생하면, 호출자는 정상적인 예외 처리를 수행해야 합니다 (예를 들어, 소유한 참조를 Py_DECREF()하고 에러값을 반환합니다).

int PyErr_WarnEx(PyObject *category, const char *message, Py_ssize_t stack_level)
Part of the 안정 ABI.

경고 메시지를 발행합니다. category 인자는 경고 범주(아래를 참조하십시오)나 NULL입니다; message 인자는 UTF-8로 인코딩된 문자열입니다. stack_level은 스택 프레임 수를 제공하는 양수입니다; 해당 스택 프레임에서 현재 실행 중인 코드 줄에서 경고가 발생합니다. stack_level이 1이면 PyErr_WarnEx()를 호출하는 함수, 2는 그 위의 함수, 등등.

경고 범주는 PyExc_Warning의 서브 클래스여야 합니다. PyExc_WarningPyExc_Exception의 서브 클래스입니다; 기본 경고 범주는 PyExc_RuntimeWarning입니다. 표준 파이썬 경고 범주는 이름이 Warning types 에 열거된 전역 변수로 제공됩니다.

경고 제어에 대한 자세한 내용은, warnings 모듈 설명서와 명령 줄 설명서에서 -W 옵션을 참조하십시오. 경고 제어를 위한 C API는 없습니다.

int PyErr_WarnExplicitObject(PyObject *category, PyObject *message, PyObject *filename, int lineno, PyObject *module, PyObject *registry)

모든 경고 어트리뷰트를 명시적으로 제어하면서 경고 메시지를 발행합니다. 이것은 파이썬 함수 warnings.warn_explicit()에 대한 간단한 래퍼입니다; 자세한 내용은 거기를 참조하십시오. 그곳에 설명된 기본 효과를 얻으려면 moduleregistry 인자를 NULL로 설정해야 합니다.

Added in version 3.4.

int PyErr_WarnExplicit(PyObject *category, const char *message, const char *filename, int lineno, const char *module, PyObject *registry)
Part of the 안정 ABI.

messagemodule이 UTF-8 인코딩된 문자열이고, filename파일시스템 인코딩과 에러 처리기로 디코딩된다는 점을 제외하면 PyErr_WarnExplicitObject() 와 유사합니다.

int PyErr_WarnFormat(PyObject *category, Py_ssize_t stack_level, const char *format, ...)
Part of the 안정 ABI.

PyErr_WarnEx()와 유사한 함수지만, PyUnicode_FromFormat()을 사용하여 경고 메시지를 포맷합니다. format은 ASCII 인코딩된 문자열입니다.

Added in version 3.2.

int PyErr_ResourceWarning(PyObject *source, Py_ssize_t stack_level, const char *format, ...)
Part of the 안정 ABI 버전 3.6 이후로.

PyErr_WarnFormat()과 유사한 함수지만, categoryResourceWarning이고 sourcewarnings.WarningMessage로 전달합니다.

Added in version 3.6.

에러 표시기 조회하기

PyObject *PyErr_Occurred()
반환값: 빌린 참조. Part of the 안정 ABI.

에러 표시기가 설정되었는지 테스트합니다. 설정되었으면, 예외 type(PyErr_Set* 함수나 PyErr_Restore()에 대한 마지막 호출의 첫 번째 인자)을 반환합니다. 설정되지 않았으면, NULL을 반환합니다. 여러분이 반환 값에 대한 참조를 소유하지 않아서, Py_DECREF() 할 필요가 없습니다.

The caller must have an attached thread state.

참고

반환 값을 특정 예외와 비교하지 마십시오; 대신 PyErr_ExceptionMatches()를 사용하십시오, 아래를 참조하십시오. (클래스 예외의 경우 예외가 클래스 대신 인스턴스이거나, 예상하는 예외의 서브 클래스일 수 있어서 비교는 실패하기 쉽습니다.)

int PyErr_ExceptionMatches(PyObject *exc)
Part of the 안정 ABI.

PyErr_GivenExceptionMatches(PyErr_Occurred(), exc)와 동등합니다. 예외가 실제로 설정되었을 때만 호출해야 합니다; 예외가 발생하지 않았으면 메모리 액세스 위반이 발생합니다.

int PyErr_GivenExceptionMatches(PyObject *given, PyObject *exc)
Part of the 안정 ABI.

given 예외가 exc의 예외 형과 일치하면 참을 반환합니다. exc가 클래스 객체이면, given이 서브 클래스의 인스턴스일 때도 참을 반환합니다. exc가 튜플이면, 튜플에 있는 모든 예외 형(그리고 서브 튜플도 재귀적으로)을 일치를 위해 검색합니다.

PyObject *PyErr_GetRaisedException(void)
반환값: 새 참조. Part of the 안정 ABI 버전 3.12 이후로.

Return the exception currently being raised, clearing the error indicator at the same time. Return NULL if the error indicator is not set.

이 함수는 예외를 포착해야 하는 코드나 에러 표시기를 일시적으로 저장하고 복원해야 하는 코드에서 사용됩니다.

예를 들어:

{
   PyObject *exc = PyErr_GetRaisedException();

   /* ... 다른 에러를 생성할 수 있는 코드 ... */

   PyErr_SetRaisedException(exc);
}

더 보기

PyErr_GetHandledException(), to save the exception currently being handled.

Added in version 3.12.

void PyErr_SetRaisedException(PyObject *exc)
Part of the 안정 ABI 버전 3.12 이후로.

Set exc as the exception currently being raised, clearing the existing exception if one is set.

경고

This call steals a reference to exc, which must be a valid exception.

Added in version 3.12.

void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
Part of the 안정 ABI.

버전 3.12부터 폐지됨: Use PyErr_GetRaisedException() instead.

주소가 전달된 세 개의 변수로 에러 표시기를 꺼냅니다. 에러 표시기가 설정되지 않았으면, 세 변수를 모두 NULL로 설정합니다. 설정되었으면, 지워지고 꺼낸 각 객체에 대한 참조를 여러분이 소유합니다. 값과 트레이스백 객체는 형 객체가 그렇지 않을 때도 NULL일 수 있습니다.

참고

이 함수는 일반적으로 예외를 포착해야 하거나 에러 표시기를 일시적으로 저장하고 복원해야 하는 레거시 코드에서만 사용됩니다.

예를 들어:

{
   PyObject *type, *value, *traceback;
   PyErr_Fetch(&type, &value, &traceback);

   /* ... 다른 에러를 생성할 수 있는 코드 ... */

   PyErr_Restore(type, value, traceback);
}
void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
Part of the 안정 ABI.

버전 3.12부터 폐지됨: Use PyErr_SetRaisedException() instead.

세 객체, type, valuetraceback으로 에러 표시기를 설정합니다. 이미 설정되어 있으면, 기존 예외를 지웁니다. 객체가 NULL이면, 에러 표시기가 지워집니다. NULL type과 함께 NULL이 아닌 value나 traceback 을 전달하지 마십시오. 예외 형은 클래스여야 합니다. 잘못된 예외 형이나 값을 전달하지 마십시오. (이러한 규칙을 위반하면 나중에 미묘한 문제가 발생합니다.) 이 호출은 각 객체에 대한 참조를 제거합니다: 호출 전에 각 객체에 대한 참조를 소유해야 하며 호출 후에는 더는 이러한 참조를 소유하지 않습니다. (이것을 이해할 수 없다면, 이 함수를 사용하지 마십시오. 경고했습니다.)

참고

이 함수는 일반적으로 에러 표시기를 일시적으로 저장하고 복원해야 하는 레거시 코드에서만 사용됩니다. 현재 에러 표시기를 저장하려면 PyErr_Fetch()를 사용하십시오.

void PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
Part of the 안정 ABI.

버전 3.12부터 폐지됨: Use PyErr_GetRaisedException() instead, to avoid any possible de-normalization.

특정 상황에서, 아래의 PyErr_Fetch()가 반환하는 값은 “비 정규화”되었을 수 있습니다. 즉, *exc는 클래스 객체이지만 *val은 같은 클래스의 인스턴스가 아닙니다. 이 함수는 이 경우 클래스를 인스턴스 화하는 데 사용할 수 있습니다. 값이 이미 정규화되어 있으면, 아무 일도 일어나지 않습니다. 지연된 정규화는 성능 향상을 위해 구현됩니다.

참고

이 함수 예외 값에 __traceback__ 어트리뷰트를 묵시적으로 설정하지 않습니다. 트레이스백을 적절하게 설정해야 하면, 다음과 같은 추가 스니펫이 필요합니다:

if (tb != NULL) {
  PyException_SetTraceback(val, tb);
}
PyObject *PyErr_GetHandledException(void)
Part of the 안정 ABI 버전 3.11 이후로.

sys.exception()이 반환하는 것과 같은, 활성 예외 인스턴스를 꺼냅니다. 이것은 새로 발생한 예외가 아니라, 이미 포착된 예외를 가리킵니다. 예외에 대한 새 참조나 NULL을 반환합니다. 인터프리터의 예외 상태를 수정하지 않습니다.

참고

이 함수는 일반적으로 예외를 처리하려는 코드에서 사용되지 않습니다. 오히려, 코드가 예외 상태를 임시로 저장하고 복원해야 할 때 사용할 수 있습니다. 예외 상태를 복원하거나 지우려면 PyErr_SetHandledException()를 사용하십시오.

Added in version 3.11.

void PyErr_SetHandledException(PyObject *exc)
Part of the 안정 ABI 버전 3.11 이후로.

sys.exception()으로 알려진 것과 같은, 활성 예외를 설정합니다. 이것은 새로 발생한 예외가 아니라, 이미 포착된 예외를 가리킵니다. 예외 상태를 지우려면, NULL을 전달하십시오.

참고

이 함수는 일반적으로 예외를 처리하려는 코드에서 사용되지 않습니다. 오히려, 코드가 예외 상태를 임시로 저장하고 복원해야 할 때 사용할 수 있습니다. 예외 상태를 얻으려면 PyErr_GetHandledException()를 사용하십시오.

Added in version 3.11.

void PyErr_GetExcInfo(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
Part of the 안정 ABI 버전 3.7 이후로.

sys.exc_info()로 알려진 것과 같은, 예외 정보의 구식 표현을 꺼냅니다. 이것은 새로 발생한 예외가 아니라, 이미 포착된 예외를 가리킵니다. 세 객체에 대한 새 참조를 반환합니다. 이 중 어느 것이든 NULL일 수 있습니다. 예외 정보 상태를 수정하지 않습니다. 이 함수는 하위 호환성을 위해 유지됩니다. 대신 PyErr_GetHandledException()을 사용하세요.

참고

이 함수는 일반적으로 예외를 처리하려는 코드에서 사용되지 않습니다. 오히려, 코드가 예외 상태를 임시로 저장하고 복원해야 할 때 사용할 수 있습니다. 예외 상태를 복원하거나 지우려면 PyErr_SetExcInfo()를 사용하십시오.

Added in version 3.3.

void PyErr_SetExcInfo(PyObject *type, PyObject *value, PyObject *traceback)
Part of the 안정 ABI 버전 3.7 이후로.

sys.exc_info()로 알려진 것과 같은, 예외 정보를 설정합니다. 이것은 새로 발생한 예외가 아니라, 이미 포착된 예외를 가리킵니다. 이 함수는 인자의 참조를 훔칩니다. 예외 상태를 지우려면, 세 인자 모두에 NULL을 전달하십시오. 이 함수는 하위 호환성을 위해 유지됩니다. 대신 PyErr_SetHandledException()을 사용하십시오.

참고

이 함수는 일반적으로 예외를 처리하려는 코드에서 사용되지 않습니다. 오히려, 코드가 예외 상태를 임시로 저장하고 복원해야 할 때 사용할 수 있습니다. 예외 상태를 읽으려면 PyErr_GetExcInfo()를 사용하십시오.

Added in version 3.3.

버전 3.11에서 변경: The type and traceback arguments are no longer used and can be NULL. The interpreter now derives them from the exception instance (the value argument). The function still steals references of all three arguments.

시그널 처리하기

int PyErr_CheckSignals()
Part of the 안정 ABI.

This function interacts with Python’s signal handling.

If the function is called from the main thread and under the main Python interpreter, it checks whether a signal has been sent to the processes and if so, invokes the corresponding signal handler. If the signal module is supported, this can invoke a signal handler written in Python.

The function attempts to handle all pending signals, and then returns 0. However, if a Python signal handler raises an exception, the error indicator is set and the function returns -1 immediately (such that other pending signals may not have been handled yet: they will be on the next PyErr_CheckSignals() invocation).

If the function is called from a non-main thread, or under a non-main Python interpreter, it does nothing and returns 0.

This function can be called by long-running C code that wants to be interruptible by user requests (such as by pressing Ctrl-C).

참고

The default Python signal handler for SIGINT raises the KeyboardInterrupt exception.

void PyErr_SetInterrupt()
Part of the 안정 ABI.

Simulate the effect of a SIGINT signal arriving. This is equivalent to PyErr_SetInterruptEx(SIGINT).

참고

This function is async-signal-safe. It can be called without an attached thread state and from a C signal handler.

int PyErr_SetInterruptEx(int signum)
Part of the 안정 ABI 버전 3.10 이후로.

시그널 도착의 효과를 시뮬레이션합니다. 다음에 PyErr_CheckSignals()가 호출되면, 주어진 시그널 번호에 대한 파이썬 시그널 처리기가 호출됩니다.

This function can be called by C code that sets up its own signal handling and wants Python signal handlers to be invoked as expected when an interruption is requested (for example when the user presses Ctrl-C to interrupt an operation).

주어진 시그널이 파이썬에서 처리되지 않으면 (signal.SIG_DFL이나 signal.SIG_IGN으로 설정되어서), 무시됩니다.

If signum is outside of the allowed range of signal numbers, -1 is returned. Otherwise, 0 is returned. The error indicator is never changed by this function.

참고

This function is async-signal-safe. It can be called without an attached thread state and from a C signal handler.

Added in version 3.10.

int PySignal_SetWakeupFd(int fd)

이 유틸리티 함수는 시그널이 수신될 때마다 시그널 번호가 단일 바이트로 기록되는 파일 기술자를 지정합니다. fd는 비 블로킹이어야 합니다. 이전의 파일 기술자를 반환합니다.

-1은 기능을 비활성화합니다; 이것이 초기 상태입니다. 이것은 파이썬의 signal.set_wakeup_fd()와 동등하지만, 에러 검사는 없습니다. fd는 유효한 파일 기술자여야 합니다. 함수는 메인 스레드에서만 호출되어야 합니다.

버전 3.5에서 변경: 윈도우에서, 함수는 이제 소켓 핸들도 지원합니다.

예외 클래스

PyObject *PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
반환값: 새 참조. Part of the 안정 ABI.

이 유틸리티 함수는 새 예외 클래스를 만들고 반환합니다. name 인자는 새 예외의 이름, module.classname 형식의 C 문자열이어야 합니다. basedict 인자는 일반적으로 NULL입니다. 이렇게 하면 Exception(C에서 PyExc_Exception으로 액세스할 수 있습니다)에서 파생된 클래스 객체가 만들어집니다.

새 클래스의 __module__ 어트리뷰트는 name 인자의 첫 번째 부분(마지막 점까지)으로 설정되고, 클래스 이름은 마지막 부분(마지막 점 뒤)으로 설정됩니다. base 인자는 대체 베이스 클래스를 지정하는 데 사용할 수 있습니다; 하나의 클래스나 클래스의 튜플일 수 있습니다. dict 인자는 클래스 변수와 메서드의 딕셔너리를 지정하는 데 사용할 수 있습니다.

PyObject *PyErr_NewExceptionWithDoc(const char *name, const char *doc, PyObject *base, PyObject *dict)
반환값: 새 참조. Part of the 안정 ABI.

새로운 예외 클래스에 독스트링을 쉽게 부여할 수 있다는 점을 제외하면 PyErr_NewException()과 같습니다: docNULL이 아니면, 예외 클래스에 대한 독스트링으로 사용됩니다.

Added in version 3.2.

int PyExceptionClass_Check(PyObject *ob)

Return non-zero if ob is an exception class, zero otherwise. This function always succeeds.

const char *PyExceptionClass_Name(PyObject *ob)
Part of the 안정 ABI 버전 3.8 이후로.

Return tp_name of the exception class ob.

예외 객체

PyObject *PyException_GetTraceback(PyObject *ex)
반환값: 새 참조. Part of the 안정 ABI.

파이썬에서 __traceback__ 어트리뷰트를 통해 액세스 할 수 있는 새로운 참조로 예외와 관련된 트레이스백을 반환합니다. 관련된 트레이스백이 없으면, NULL을 반환합니다.

int PyException_SetTraceback(PyObject *ex, PyObject *tb)
Part of the 안정 ABI.

예외와 관련된 트레이스백을 tb로 설정합니다. 지우려면 Py_None을 사용하십시오.

PyObject *PyException_GetContext(PyObject *ex)
반환값: 새 참조. Part of the 안정 ABI.

파이썬에서 __context__ 어트리뷰트를 통해 액세스 할 수 있는 새 참조로 예외와 연관된 컨텍스트(다른 예외 인스턴스, 이것을 처리하는 도중 ex가 발생했습니다)를 반환합니다. 연결된 컨텍스트가 없으면 NULL을 반환합니다.

void PyException_SetContext(PyObject *ex, PyObject *ctx)
Part of the 안정 ABI.

예외와 연관된 컨텍스트를 ctx로 설정합니다. 지우려면 NULL을 사용하십시오. ctx가 예외 인스턴스인지 확인하는 형 검사는 없습니다. 이것은 ctx에 대한 참조를 훔칩니다.

PyObject *PyException_GetCause(PyObject *ex)
반환값: 새 참조. Part of the 안정 ABI.

파이썬에서 __cause__ 어트리뷰트를 통해 액세스 할 수 있는 새 참조로 예외와 관련된 원인(예외 인스턴스나 None, raise ... from ...으로 설정됩니다)을 반환합니다.

void PyException_SetCause(PyObject *ex, PyObject *cause)
Part of the 안정 ABI.

예외와 관련된 원인을 cause로 설정합니다. 지우려면 NULL을 사용하십시오. cause가 예외 인스턴스나 None인지 확인하는 형 검사는 없습니다. 이것은 cause에 대한 참조를 훔칩니다.

__suppress_context__ 어트리뷰트는 이 함수에 의해 묵시적으로 True로 설정됩니다.

PyObject *PyException_GetArgs(PyObject *ex)
반환값: 새 참조. Part of the 안정 ABI 버전 3.12 이후로.

Return args of exception ex.

void PyException_SetArgs(PyObject *ex, PyObject *args)
Part of the 안정 ABI 버전 3.12 이후로.

Set args of exception ex to args.

PyObject *PyUnstable_Exc_PrepReraiseStar(PyObject *orig, PyObject *excs)
이것은 불안정 API. It may change without warning in minor releases.

Implement part of the interpreter’s implementation of except*. orig is the original exception that was caught, and excs is the list of the exceptions that need to be raised. This list contains the unhandled part of orig, if any, as well as the exceptions that were raised from the except* clauses (so they have a different traceback from orig) and those that were reraised (and have the same traceback as orig). Return the ExceptionGroup that needs to be reraised in the end, or None if there is nothing to reraise.

Added in version 3.12.

유니코드 예외 객체

다음 함수는 C에서 유니코드 예외를 만들고 수정하는 데 사용됩니다.

PyObject *PyUnicodeDecodeError_Create(const char *encoding, const char *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason)
반환값: 새 참조. Part of the 안정 ABI.

encoding, object, length, start, endreason 어트리뷰트를 사용하여 UnicodeDecodeError 객체를 만듭니다. encodingreason은 UTF-8로 인코딩된 문자열입니다.

PyObject *PyUnicodeDecodeError_GetEncoding(PyObject *exc)
PyObject *PyUnicodeEncodeError_GetEncoding(PyObject *exc)
반환값: 새 참조. Part of the 안정 ABI.

주어진 예외 객체의 encoding 어트리뷰트를 반환합니다.

PyObject *PyUnicodeDecodeError_GetObject(PyObject *exc)
PyObject *PyUnicodeEncodeError_GetObject(PyObject *exc)
PyObject *PyUnicodeTranslateError_GetObject(PyObject *exc)
반환값: 새 참조. Part of the 안정 ABI.

주어진 예외 객체의 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)
Part of the 안정 ABI.

주어진 예외 객체의 start 어트리뷰트를 가져와서 *start에 배치합니다. startNULL이 아니어야 합니다. 성공하면 0을, 실패하면 -1을 반환합니다.

If the UnicodeError.object is an empty sequence, the resulting start is 0. Otherwise, it is clipped to [0, len(object) - 1].

더 보기

UnicodeError.start

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)
Part of the 안정 ABI.

Set the start attribute of the given exception object to start. Return 0 on success, -1 on failure.

참고

While passing a negative start does not raise an exception, the corresponding getters will not consider it as a relative offset.

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)
Part of the 안정 ABI.

주어진 예외 객체의 end 어트리뷰트를 가져와서 *end에 배치합니다. endNULL이 아니어야 합니다. 성공하면 0을, 실패하면 -1을 반환합니다.

If the UnicodeError.object is an empty sequence, the resulting end is 0. Otherwise, it is clipped to [1, len(object)].

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)
Part of the 안정 ABI.

주어진 예외 객체의 end 어트리뷰트를 end로 설정합니다. 성공하면 0을, 실패하면 -1을 반환합니다.

더 보기

UnicodeError.end

PyObject *PyUnicodeDecodeError_GetReason(PyObject *exc)
PyObject *PyUnicodeEncodeError_GetReason(PyObject *exc)
PyObject *PyUnicodeTranslateError_GetReason(PyObject *exc)
반환값: 새 참조. Part of the 안정 ABI.

주어진 예외 객체의 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)
Part of the 안정 ABI.

주어진 예외 객체의 reason 어트리뷰트를 reason으로 설정합니다. 성공하면 0을, 실패하면 -1을 반환합니다.

재귀 제어

이 두 함수는 코어와 확장 모듈 모두에서 C 수준에서 안전한 재귀 호출을 수행하는 방법을 제공합니다. 재귀 코드가 반드시 파이썬 코드를 호출하지 않는 경우 필요합니다 (파이썬 코드는 재귀 깊이를 자동으로 추적합니다). 호출 프로토콜이 재귀 처리를 처리하기 때문에 tp_call 구현에도 필요하지 않습니다.

int Py_EnterRecursiveCall(const char *where)
Part of the 안정 ABI 버전 3.9 이후로.

재귀적 C 수준 호출이 막 수행되려고 하는 지점을 표시합니다.

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

where는 재귀 깊이 제한으로 인한 RecursionError 메시지에 이어붙일 " in instance check"와 같은 UTF-8 인코딩된 문자열이어야 합니다.

버전 3.9에서 변경: 이 함수는 이제 제한된 API에서도 사용할 수 있습니다.

void Py_LeaveRecursiveCall(void)
Part of the 안정 ABI 버전 3.9 이후로.

Py_EnterRecursiveCall() 을 종료합니다. Py_EnterRecursiveCall() 의 각 성공적인 호출마다 한 번씩 호출되어야 합니다.

버전 3.9에서 변경: 이 함수는 이제 제한된 API에서도 사용할 수 있습니다.

컨테이너형에 대해 tp_repr을 올바르게 구현하려면 특별한 재귀 처리가 필요합니다. 스택을 보호하는 것 외에도, tp_repr은 순환을 방지하기 위해 객체를 추적해야 합니다. 다음 두 함수는 이 기능을 쉽게 만듭니다. 사실상, 이들은 reprlib.recursive_repr()에 대한 C 동등물입니다.

int Py_ReprEnter(PyObject *object)
Part of the 안정 ABI.

순환을 감지하기 위해 tp_repr 구현 시작 시 호출됩니다.

객체가 이미 처리되었으면, 함수는 양의 정수를 반환합니다. 이 경우 tp_repr 구현은 순환을 나타내는 문자열 객체를 반환해야 합니다. 예를 들어, dict 객체는 {...}를 반환하고 list 객체는 [...]를 반환합니다.

재귀 제한에 도달하면 함수는 음의 정수를 반환합니다. 이 경우 tp_repr 구현은 일반적으로 NULL을 반환해야 합니다.

그렇지 않으면, 함수는 0을 반환하고 tp_repr 구현은 정상적으로 계속될 수 있습니다.

void Py_ReprLeave(PyObject *object)
Part of the 안정 ABI.

Py_ReprEnter()를 종료합니다. 0을 반환하는 Py_ReprEnter() 호출마다 한 번씩 호출해야 합니다.

Exception and warning types

All standard Python exceptions and 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:

Exception types

C name

Python name

PyObject *PyExc_BaseException
Part of the 안정 ABI.

BaseException

PyObject *PyExc_BaseExceptionGroup
Part of the 안정 ABI 버전 3.11 이후로.

BaseExceptionGroup

PyObject *PyExc_Exception
Part of the 안정 ABI.

Exception

PyObject *PyExc_ArithmeticError
Part of the 안정 ABI.

ArithmeticError

PyObject *PyExc_AssertionError
Part of the 안정 ABI.

AssertionError

PyObject *PyExc_AttributeError
Part of the 안정 ABI.

AttributeError

PyObject *PyExc_BlockingIOError
Part of the 안정 ABI 버전 3.7 이후로.

BlockingIOError

PyObject *PyExc_BrokenPipeError
Part of the 안정 ABI 버전 3.7 이후로.

BrokenPipeError

PyObject *PyExc_BufferError
Part of the 안정 ABI.

BufferError

PyObject *PyExc_ChildProcessError
Part of the 안정 ABI 버전 3.7 이후로.

ChildProcessError

PyObject *PyExc_ConnectionAbortedError
Part of the 안정 ABI 버전 3.7 이후로.

ConnectionAbortedError

PyObject *PyExc_ConnectionError
Part of the 안정 ABI 버전 3.7 이후로.

ConnectionError

PyObject *PyExc_ConnectionRefusedError
Part of the 안정 ABI 버전 3.7 이후로.

ConnectionRefusedError

PyObject *PyExc_ConnectionResetError
Part of the 안정 ABI 버전 3.7 이후로.

ConnectionResetError

PyObject *PyExc_EOFError
Part of the 안정 ABI.

EOFError

PyObject *PyExc_FileExistsError
Part of the 안정 ABI 버전 3.7 이후로.

FileExistsError

PyObject *PyExc_FileNotFoundError
Part of the 안정 ABI 버전 3.7 이후로.

FileNotFoundError

PyObject *PyExc_FloatingPointError
Part of the 안정 ABI.

FloatingPointError

PyObject *PyExc_GeneratorExit
Part of the 안정 ABI.

GeneratorExit

PyObject *PyExc_ImportError
Part of the 안정 ABI.

ImportError

PyObject *PyExc_IndentationError
Part of the 안정 ABI.

IndentationError

PyObject *PyExc_IndexError
Part of the 안정 ABI.

IndexError

PyObject *PyExc_InterruptedError
Part of the 안정 ABI 버전 3.7 이후로.

InterruptedError

PyObject *PyExc_IsADirectoryError
Part of the 안정 ABI 버전 3.7 이후로.

IsADirectoryError

PyObject *PyExc_KeyError
Part of the 안정 ABI.

KeyError

PyObject *PyExc_KeyboardInterrupt
Part of the 안정 ABI.

KeyboardInterrupt

PyObject *PyExc_LookupError
Part of the 안정 ABI.

LookupError

PyObject *PyExc_MemoryError
Part of the 안정 ABI.

MemoryError

PyObject *PyExc_ModuleNotFoundError
Part of the 안정 ABI 버전 3.6 이후로.

ModuleNotFoundError

PyObject *PyExc_NameError
Part of the 안정 ABI.

NameError

PyObject *PyExc_NotADirectoryError
Part of the 안정 ABI 버전 3.7 이후로.

NotADirectoryError

PyObject *PyExc_NotImplementedError
Part of the 안정 ABI.

NotImplementedError

PyObject *PyExc_OSError
Part of the 안정 ABI.

OSError

PyObject *PyExc_OverflowError
Part of the 안정 ABI.

OverflowError

PyObject *PyExc_PermissionError
Part of the 안정 ABI 버전 3.7 이후로.

PermissionError

PyObject *PyExc_ProcessLookupError
Part of the 안정 ABI 버전 3.7 이후로.

ProcessLookupError

PyObject *PyExc_PythonFinalizationError

PythonFinalizationError

PyObject *PyExc_RecursionError
Part of the 안정 ABI 버전 3.7 이후로.

RecursionError

PyObject *PyExc_ReferenceError
Part of the 안정 ABI.

ReferenceError

PyObject *PyExc_RuntimeError
Part of the 안정 ABI.

RuntimeError

PyObject *PyExc_StopAsyncIteration
Part of the 안정 ABI 버전 3.7 이후로.

StopAsyncIteration

PyObject *PyExc_StopIteration
Part of the 안정 ABI.

StopIteration

PyObject *PyExc_SyntaxError
Part of the 안정 ABI.

SyntaxError

PyObject *PyExc_SystemError
Part of the 안정 ABI.

SystemError

PyObject *PyExc_SystemExit
Part of the 안정 ABI.

SystemExit

PyObject *PyExc_TabError
Part of the 안정 ABI.

TabError

PyObject *PyExc_TimeoutError
Part of the 안정 ABI 버전 3.7 이후로.

TimeoutError

PyObject *PyExc_TypeError
Part of the 안정 ABI.

TypeError

PyObject *PyExc_UnboundLocalError
Part of the 안정 ABI.

UnboundLocalError

PyObject *PyExc_UnicodeDecodeError
Part of the 안정 ABI.

UnicodeDecodeError

PyObject *PyExc_UnicodeEncodeError
Part of the 안정 ABI.

UnicodeEncodeError

PyObject *PyExc_UnicodeError
Part of the 안정 ABI.

UnicodeError

PyObject *PyExc_UnicodeTranslateError
Part of the 안정 ABI.

UnicodeTranslateError

PyObject *PyExc_ValueError
Part of the 안정 ABI.

ValueError

PyObject *PyExc_ZeroDivisionError
Part of the 안정 ABI.

ZeroDivisionError

Added in version 3.5: PyExc_StopAsyncIterationPyExc_RecursionError.

Added in version 3.6: PyExc_ModuleNotFoundError.

Added in version 3.11: PyExc_BaseExceptionGroup.

OSError aliases

The following are a compatibility aliases to PyExc_OSError.

버전 3.3에서 변경: 이러한 별칭은 별도의 예외 형이었습니다.

C name

Python name

노트

PyObject *PyExc_EnvironmentError
Part of the 안정 ABI.

OSError

PyObject *PyExc_IOError
Part of the 안정 ABI.

OSError

PyObject *PyExc_WindowsError
Part of the 안정 ABI on Windows 버전 3.7 이후로.

OSError

[win]

노트:

[win]

PyExc_WindowsError is only defined on Windows; protect code that uses this by testing that the preprocessor macro MS_WINDOWS is defined.

Warning types

C name

Python name

PyObject *PyExc_Warning
Part of the 안정 ABI.

Warning

PyObject *PyExc_BytesWarning
Part of the 안정 ABI.

BytesWarning

PyObject *PyExc_DeprecationWarning
Part of the 안정 ABI.

DeprecationWarning

PyObject *PyExc_EncodingWarning
Part of the 안정 ABI 버전 3.10 이후로.

EncodingWarning

PyObject *PyExc_FutureWarning
Part of the 안정 ABI.

FutureWarning

PyObject *PyExc_ImportWarning
Part of the 안정 ABI.

ImportWarning

PyObject *PyExc_PendingDeprecationWarning
Part of the 안정 ABI.

PendingDeprecationWarning

PyObject *PyExc_ResourceWarning
Part of the 안정 ABI 버전 3.7 이후로.

ResourceWarning

PyObject *PyExc_RuntimeWarning
Part of the 안정 ABI.

RuntimeWarning

PyObject *PyExc_SyntaxWarning
Part of the 안정 ABI.

SyntaxWarning

PyObject *PyExc_UnicodeWarning
Part of the 안정 ABI.

UnicodeWarning

PyObject *PyExc_UserWarning
Part of the 안정 ABI.

UserWarning

Added in version 3.2: PyExc_ResourceWarning.

Added in version 3.10: PyExc_EncodingWarning.