Exception handling wart in Python

Leo Lipelis aeoo at myspamrealbox.com
Sat Nov 3 00:08:41 CET 2001

On Fri, 02 Nov 2001 14:37:22 -0500, Huaiyu Zhu wrote:

> On Thu, 01 Nov 2001 19:35:46 -0500, Leo Lipelis <aeoo at myrealbox.com>
> wrote:
> Exception is a mechanism to treat low probability situations so that
> they do not distract the main flow of the program.  Python allows you to
> ignore them or handle them any way you like, so that you can concentrate
> on the main thing you are doing.  Java forces you to treat them all
> explicitly, which sort of defeats its purpose.  It becomes essentially a
> glorified condition-goto structure.  Since in any real world situation
> the probability distribution of cases are far from uniform, I find
> Python style exceptions far more efficient.

I agree with your sentiment here.  You present your points clearly here.
However, what I want does not take away anything from Python as it is now.
 It's not something that would *force* anything, or even something that
would *have* to become part of the compiler.  It would be a standard tool
that would be available to those who *want* to check if they are leaving
out some unhandled exceptions.

To actually *wait* for most common exceptions to happen is definitely one
strategy.  But somehow I don't feel that this is a "scientific" (for the
lack of the better word) way of doing it.

Regarding the binding problem with:

a, b = c(d)

This really goes to the issue of generic programming.  It seems like every
function in Python is generic, but in reality it is not so.  In the real
world (in Python) there is a class of functions that can be and truly are
generic, and there is a much bigger class of functions (in Python) that
really only make sense with particular data types.  Perhaps, it would be a
good idea to give the exception flow checker tool some hints in the source
code about the function being generic or not.  That way you can avoid the
problem of seemingly being asked to handle *all* possible exceptions in
generic functions.  Or, perhaps, it might be a good idea to assume that
all generic functions do not belong inside class objects.  Perhaps only
class object methods should be checked for exception handling?

More information about the Python-list mailing list