Try block problem

Skip Montanaro skip at
Tue Nov 20 14:41:05 CET 2001

    Marcin> Tue, 20 Nov 2001 05:37:41 -0600, Skip Montanaro <skip at> pisze:
    >> The thing that is perhaps slightly misleading is the use of the "try"
    >> keyword to begin both constructs.  There's really no "try"
    >> connotation to try/finally.

    Marcin> Maybe it's because try:except: would have to be used to simulate
    Marcin> try:finally: if it wasn't available natively.

I don't know how you'd do this.  For example:

    def f(d):
            return d.keys()

How would that be handled with try/except?  (IOW, where's the exception?)
The natural way to code it (without try/finally) would be

    def f(d):
        keys = d.keys()
        return keys

    Marcin> In other words try:finally: is one of things which do something
    Marcin> non-trivial with exceptions instead of silently propagating them
    Marcin> up.

Try/finally isn't directly concerned with exceptions at all.

Skip Montanaro (skip at -

More information about the Python-list mailing list