No return to the parent function

MRAB python at mrabarnett.plus.com
Tue Feb 2 12:08:54 EST 2010


Joan Miller wrote:
> I've a main function called i.e. *foo()* which has a block of code
> that is repetead several times (for the error catching code and error
> reporting), but that code has a return to exit of *foo()*
> 
> -----------
> foo():
>   ...
>     if self.background:
>         _log.exception(str(error))
>         return ReturnCode.ERROR, None
>     else:
>         raise NameError(error)
> 
> -----------
> 
> So I would tu put that code block into a separated function (*throw()
> *), but the problem is that it returns to the parent function (foo()).
> How to solve it?

Call it in a return statement.



More information about the Python-list mailing list