try/except/finally

Rustom Mody rustompmody at gmail.com
Sat Jun 7 23:58:42 EDT 2014


On Sunday, June 8, 2014 5:17:21 AM UTC+5:30, Chris Angelico wrote:
> On Sun, Jun 8, 2014 at 8:49 AM, Ethan Furman  wrote:
> > I don't remember if I almost had this in real code or if I learned about it
> > first, but it can definitely be a gotcha. It seems to me that if the try
> > block exits with an explicit return, and then the finally block exits with
> > an explicit return, some kind of error ought to be raised.

> I'd go a little simpler: A return statement inside a finally block is
> code smell.

Some people¹ think that gotos are a code-smell.

And since both return and exceptions are thinly veiled gotos, what we
have here are two smells outsmelling each other.

¹ I am not exactly those people.
A chap called E W Dijkstra made the statement: "Goto statement considered 
harmful" and became famous.
The chap who taught me programming said to me: "What the goto does to 
control structure, the assignment does to data structure"
He did not become famous.
However in my view he made the more intelligent statement



More information about the Python-list mailing list