[Python-Dev] Raising OSError concrete classes from errno code

Andrew Svetlov andrew.svetlov at gmail.com
Tue Dec 25 22:55:06 CET 2012

Currently we have exception tree of classes inherited from OSError
When we use C API we can call PyErr_SetFromErrno and
PyErr_SetFromErrnoWithFilename[Object] functions.
This ones raise concrete exception class (FileNotFoundError for
example) looking on implicit errno value.
I cannot see the way to do it from python.

Maybe adding builtin like exception_from_errno(errno, filename=None)
make some value?
Function returns exception instance, concrete class depends of errno value

For example if I've got EPOLLERR from poller call I can get error code
via s.getsockopt(SOL_SOCKET, SO_ERROR)
but I cannot raise concrete exception from given errno code.

Andrew Svetlov

More information about the Python-Dev mailing list