Try... except....Try again?

Xavier Ho contact at
Fri Jul 17 18:07:13 EDT 2009

On Sat, Jul 18, 2009 at 5:58 AM, Lie Ryan <lie.1296 at> wrote:

> If you're looking for speed, you should be aware that a failed
> try-clause is quite expensive in python and often (as in this case)
> codes using exception can be less readable than the one without since a
> program's flow in the case of exception is not linear (the non-linear
> execution is useful for quickly breaking out from nests of clauses, but
> not necessary in this case).

Was not aware that myself. Noted.

> Semantically, it is also wrong. Not finding the n'th prime in the cache
> is not really an exceptional case.
> If you insists on using a try-except clause, use it this way:
> Well, I don't have to use try-except. I think I got another idea though. I
could use an internal counter to keep track of how many prime numbers have
generated, and if not enough, generate more.


Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: contact at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list