Overuse of try/except/else?

Hans Georg Schaathun hg at schaathun.net
Tue May 10 08:10:11 EDT 2011


On Tue, 10 May 2011 07:36:42 -0400, Adam Tauno Williams
  <awilliam at whitemice.org> wrote:
:  On Mon, 2011-05-09 at 19:40 -0500, Kyle T. Jones wrote:
: > It has been hard for me to determine what would constitute overuse.
: 
:  The chronic problem is under use; so I wouldn't worry much about it.
: 
:  try/except should occur as often as is required for the application to
:  either deal gracefully with the condition or report *meaningful* error
:  messages to the user/administrator.

So overuse is really when you cannot do anything meaningful about 
the exception.  The two interesting questions are really
  1. where and when to catch a given exception
  2. at what stage of the development cycle catching a particular
    (class of) exception should become a priority

There is a potential overuse of exceptions, where they are used for
quite ordinary and frequent (i.e. not exceptional) conditions, and
the information could be passed through the return value instead.
Exceptions is a very flexible, but also rather expensive means of
communications.  You can, actually, write any program using raise 
instead of return.  That would be overuse.

-- 
:-- Hans Georg



More information about the Python-list mailing list