[Tutor] try except continue

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Jul 29 00:40:33 CEST 2005



On Thu, 28 Jul 2005 tpc247 at gmail.com wrote:

> ideally what I'd like is for my procedural program, when it runs through
> its steps and encounters an error, to log the error and pick up where it
> left off and keep going.
>
> so for the execution of someProcedure(), I want it to print the error
> and continue running through the rest of someProcedure().  Is this
> possible ?

Hi Tpc,

I think there's some confusion about the role of 'continue'; it's doesn't
have anything to do with exception handling.

The following example might help:

######
>>> def showDivision(n):
...     try:
...         for i in range(10):
...             print i, i / n
...     except ZeroDivisionError:
...         print "Huh?!"
...     print "All done!"
...
>>> showDivision(5)
0 0
1 0
2 0
3 0
4 0
5 1
6 1
7 1
8 1
9 1
All done!
>>> showDivision(0)
0 Huh?!
All done!
>>>
######


Does this help to clear thing up?



More information about the Tutor mailing list