Might have a stack overflow issue, if it retries too many times?

"alex23" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On May 22, 6:15 pm, Karlo Lozovina <[EMAIL PROTECTED]> wrote:
>> Because when you expect exception to occur on something like 0.01% of
>> cases, and you have 4 or 5 exceptions and the code to test for each
>> conditions that cause exceptions is quite long and burried deep inside
>> some other code it's much better to do it this way ;). Too bad there's no
>> syntactic sugar for doing this kind of try-except loop.
>
> I'm surprised your unit tests let it get to such a state... ;)
>
> How about something like this?
>
>    retry, total_fail = False, False
>    try:
>        some_function()
>    except SomeException:
>        some_function2()
>        some_function3()
>        retry = True
>    finally:
>        if retry:
>            try:
>                some_function()
>            except SomeException:
>                total_fail = True
>
> Using 'finally' seems more explicit about it being part of the
> exception handling than using a loop construct.
>
> Actually, this is even more direct:
>
>    try:
>        some_function()
>    except SomeException:
>        some_function2()
>        some_function3()
>        try:
>            some_function()
>        except SomeException:
>            raise SomeError 


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to