converting a nested try/except statement into try/except/else

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Thu Aug 10 16:05:01 EDT 2006


John Salerno a écrit :
> Bruno Desthuilliers wrote:
> 
>>      try:
>>          if int(text) <= 0: raise ValueError
> 
> 
> Hmm, I'm actually not so sure about this line now. It doesn't seem right 
> to raise a ValueError when the result of the expression is negative, 
> because even though it's a problem for my program, it isn't really a 
> "ValueError," right?

It's obviously a ValueError if your program needs a strictly positive 
integer. But anyway, you don't care: this error is raised just so it get 
caught on the next line...



More information about the Python-list mailing list