How robust is Python ?

Donn Cave donn at u.washington.edu
Fri Jan 12 13:07:58 EST 2001


Quoth "Sandipan Gangopadhyay" <sandipan at vsnl.com>:
[ ... re top level exception handlers ... ]

| I want this in my code, but came across a problem -
|
| while binAliveMarker:
|   if binIWannaStartAgain:
|     time.sleep(1)
|     continue
|   work code ...
|
| If I try a catch-all except, continue hits except on the outer level rather
| than while. Probably the reason that it results in syntax error.
|
| while binAliveMarker:
|   try:
|     if binWannaStartAgainLater:
|       time.sleep(1)
|       continue
|     work code ...
|   except:
|     pass
|
| Any suggestions to make it work with continue (or an alternative) ? Apart
| from removing continue completely by making the work code inside an else ?

Why apart from that?

I guess we've already covered the "try: continue" issue:  "try: continue"
just isn't supported (though the more useful "try: ... except: continue"
does work.)  Readable flow control inside a loop is very doable.  It's
hard for me to see that try: continue would really improve on that -
on the contrary, continue is liable to detract from readability if it's
used in conjunction with too many other flow control options.  I think
"goto" would be fun, too, but I can see why in some ways we're better
off without it.

But back to the subject, I would be interested in more concrete
examples of what exceptions we're liable to catch in a case like that.
I have used top level handlers, but only as basically an alternative to
the traceback, not to resume execution.  I think the initial proposal
was to execute the program again from scratch after it exits, and it's
pretty obvious what that's about.  But after catching some random
exception at the top of the program, I would be concerned that the
program might be in a compromised state and not really fit to go back
to work.  And would that really catch the kind of lossage that could
break a correctly written Python program, or do those things usually
break the interpreter directly?

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list