[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: 

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: 

   # code that might have bugs
except (SystemExit, KeyboardInterrupt):
   # exceptions I do not want to catch
    # all other exceptions


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
>(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

More information about the Tutor mailing list