A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2001-November/018396.html below:

[Python-Dev] Proposal - KeyboardInterrupt should inherit directly from Exception

[Python-Dev] Proposal - KeyboardInterrupt should inherit directly from Exception [Python-Dev] Proposal - KeyboardInterrupt should inherit directly from ExceptionGreg Ward gward@python.net
Wed, 7 Nov 2001 08:33:49 -0500
On 07 November 2001, Skip Montanaro said:
> I have a simple proposal: Change the exception class hierarchy
> slightly, so that exceptions you generally will want to re-raise don't
> inherit from StandardError.  Currently, SystemExit, StopIteration and
> Warning inherit directly from Exception.  I suggest that
> KeyboardInterrupt should also inherit from Exception, and not
> StandardError.

Sounds sensible to me.

> That way, the standard catch all except clause can be
> 
>     try:
>         fragile code
>     except StandardError:
>         recover

So "fragile code" would be the main loop of a GUI or server, or an eval
or exec of user-supplied code (eg. a config file that happens to be
Python source) -- that sort of thing?  Those are the only legitimate
places that I can think of "except: ...", and changing that to
"except StandardError: ..." seems like a tiny hardship that buys a
little something.

Hmmm... does anyone else habitually write

  if __name__ == "__main__":
      try:
          main()
      except KeyboardInterrupt:
          sys.exit("interrupted")

And is anyone else sick of doing this?

        Greg
-- 
Greg Ward - nerd                                        gward@python.net
http://starship.python.net/~gward/
There are no stupid questions -- only stupid people.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4