[py-dev] revising exception handling / help appreciated
holger krekel
hpk at trillke.net
Sun Jan 2 14:00:02 CET 2005
Hi py-dev,
i was wondering if anybody has any helpful opinions or
suggestions on the following so far rather undocumented
feature regarding exception-handling. It's one of the
fundamental things that prevents releasing the py lib and
py.test.
Currently, especially the local path implementation converts
IOErrors/OSErrors to specific new classes derived from the
"errno" attribute of those errors. This makes it possible to do
something like:
try:
do_something_with(path)
except py.path.NotFound:
...
except py.path.PermissionDenied:
...
and so on. Other path implementations (the subversion
ones especially) try to raise such exceptions as well.
Now the question is if the above exceptions shouldn't better
have their names derived from what is in the "errno" module.
Refering to these posix-standard names avoids to learn new
names and their semantics. I would hope these names also
make sense on non-unix environments.
The above example would probably become:
try:
do_something_with(path)
except py.error.ENOENT:
...
except py.error.EPERM:
...
This error-conversion would/should then more easily
become pervasive through the library, e.g. py.execnet
(http://codespeak.net/py/current/doc/execnet.html)
would probably also raise such exceptions if applicable.
Also the svn implementations would try to fit exceptions
as good as possible into this naming.
Exceptions arising in path implementations may even derive
from something like py.path.Error in order to allow easier
"catch-all-path-errors" handling. Not sure about this, though,
as the distinction may be too vague.
Any opinions?
cheers and a happy new year,
holger
More information about the Pytest-dev
mailing list