Error Handling

Errors are indicated by returning NULL to the interpreter. Prior to returning NULL, an exception should be set or cleared using one of the following functions:

					void PyErr_Clear()
				

Clears any previously raised exceptions.

					PyObject *PyErr_Occurred()
				

Checks to see whether an error has been generated. If so, returns the current exception object. Otherwise, returns NULL.

					void PyErr_NoMemory()
				

Raises a MemoryError exception.

					void PyErr_SetFromErrno(PyObject *exc)
				

Raises an exception. exc is an exception object. The value of the exception is taken from the errno variable in the C library.

					void PyErr_SetFromErrnoWithFilename(PyObject *exc, char *filename)
				

Like PyErr_SetFromErrno() but includes the filename in the exception value ...

Get Python Essential Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.