[Tutor] smtplib exceptions are based on Exception class

Kent Johnson kent_johnson at skillsoft.com
Fri Aug 27 21:56:56 CEST 2004


AFAIK this is typical, e.g.

 >>> import socket
 >>> socket.error.__bases__
(<class exceptions.Exception at 0x00764510>,)
 >>> import zlib
 >>> zlib.error.__bases__
(<class exceptions.Exception at 0x00764510>,)
 >>> import binhex
 >>> binhex.Error.__bases__
(<class exceptions.Exception at 0x00764510>,)

It is also the style used in the Tutorial: 
http://docs.python.org/tut/node10.html#SECTION0010500000000000000000

On the other hand, searching comp.lang.python for StandardError shows you 
aren't the first person to have this question. Arguably it is a design 
error that the library exceptions don't extend StandardError. This post has 
a suggested way to write your try block: 
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&c2coff=1&th=2520f2348aca78b&rnum=7

try:
   # code that might have bugs
except (SystemExit, KeyboardInterrupt):
   # exceptions I do not want to catch
    raise
except:
    # all other exceptions
   sys.stderr.write(...)
   traceback.print_exc(file=sys.stderr)

Kent

At 03:21 PM 8/27/2004 -0400, Lloyd Kvam wrote:
>from smtplib:
>
>class SMTPException(Exception):
>     """Base class for all exceptions raised by this module."""
>
>Shouldn't the base class be StandardError or a class derived from
>StandardError?  I didn't want to file a bug without getting another
>opinion.
>
>(I discovered it the hard way when my except StandardError block was
>unable to deal with email errors.)
>
>
>--
>
>Lloyd Kvam
>Venix Corp.
>1 Court Street, Suite 378
>Lebanon, NH 03766-1358
>
>voice:  603-653-8139
>fax:    320-210-3409 (changed Aug 26, 2004)
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list