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

Fred L. Drake, Jr. fdrake@acm.org
Wed, 7 Nov 2001 09:41:08 -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 reasonable to me.
Greg Ward writes:
 > Hmmm... does anyone else habitually write
 > 
 > if __name__ == "__main__":
 > try:
 > main()
 > except KeyboardInterrupt:
 > sys.exit("interrupted")
 It must be you, Greg! ;-) The only thing I can think of that I do
similar to that is:
import errno
if __name__ == "__main__":
 # do setup stuff...
 ...
 # output result to file...
 try:
 write_result() # or whatever it really is...
 except IOError, e:
 if e.errno != errno.EPIPE:
 raise
 -Fred
-- 
Fred L. Drake, Jr. <fdrake at acm.org>
PythonLabs at Zope Corporation

AltStyle によって変換されたページ (->オリジナル) /