Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why Error is derived from EnvironmentError in shutil.py?

2 views
Skip to first unread message

Peng Yu

unread,
Nov 11, 2009, 11:46:34 PM11/11/09
to pytho...@python.org
I see Error is derived from EnvironmentError in shutil.py.

class Error(EnvironmentError):
pass

I'm wondering why EnvironmentError can not be raised directly. Why
Error is raised instead?

Steven D'Aprano

unread,
Nov 11, 2009, 11:55:50 PM11/11/09
to


Probably to do with the personal taste of the author.

http://docs.python.org/library/shutil.html#shutil.Error


--
Steven

alex23

unread,
Nov 12, 2009, 1:00:48 AM11/12/09
to

This way you can explicitly trap on shutil.Error and not intercept any
other EnvironmentError that might be raised.

And as it's a descendent of EnvironmentError, it can still be caught
by any handlers looking for such exceptions.

Peng Yu

unread,
Nov 12, 2009, 10:10:24 AM11/12/09
to pytho...@python.org

It is true that an exception class is usually defined in a module and
all the exceptions raised in this module should be of this derived
class? Is it the general practice in python?

Chris Rebert

unread,
Nov 12, 2009, 10:37:41 AM11/12/09
to Peng Yu, pytho...@python.org
On Thu, Nov 12, 2009 at 7:10 AM, Peng Yu <peng...@gmail.com> wrote:
> On Thu, Nov 12, 2009 at 12:00 AM, alex23 <wuw...@gmail.com> wrote:
> It is true that an exception class is usually defined in a module and
> all the exceptions raised in this module should be of this derived
> class? Is it the general practice in python?

It is common, but not universal. Several of the modules in the stdlib
use the technique.

Cheers,
Chris
--
http://blog.rebertia.com

0 new messages