Suggesting the use of StandardError as base of error Exceptions.

Steven Bethard steven.bethard at gmail.com
Mon Mar 6 11:11:06 EST 2006


Antoon Pardon wrote:
> I then took a look at http://docs.python.org/lib/module-exceptions.html
> which describes the exception heirarchy as follows:
> 
>     Exception
>      +-- SystemExit
>      +-- StopIteration
>      +-- StandardError
>      |   +
>      |   + All kind of error exceptions
>      |   + 
>      +---Warning
>          +
>          + All kind of warnings
>          +
> 
> and came to the conclusion, that it would be better to write my code
> as follows:
> 
> for case in all_cases:
>   try:
>     treat(case)
>   except StandardError, ErrInfo:
>     generate_traceback()

You've already been pointed to `PEP 352`_, but just to highlight the 
salient point, I believe what you want to write is::

     try:
         ...
     except (KeyboardInterrupt, SystemExit):
         raise
     except:
         ...

.. _PEP 352: http://www.python.org/peps/pep-0352.html

STeVe



More information about the Python-list mailing list