THIS Broke My Code In Python #python #code #programming

preview_player
Показать описание
This broke my code in Python. #python #code #programming
Рекомендации по теме
Комментарии
Автор

That is because you're not supposed to return anything from the finally block. It's mainly meant to clean up any side effects such as closing a file or aborting a network request.

tutorialsandgaminghelp
Автор

putting a return in the finally block should be a syntax error.

kellymoses
Автор

finally works that way in every language not just python

BenMeddeb
Автор

That's what I like to call a 5 o clock error 😂

NeumsFor
Автор

I didn't know this. I do a lot of C++ and this is an insanely nice feature for writing failure safe code. You won't normally use returns here, but you will be able to run "undo" steps in the finally block if you run into an exception. It's like RAII (guard scope) without creating an object.

skylarscott
Автор

return is supposed to LEAVE the entire function.
But I love the weasel excuse in the docs :
"When  passes control out of a  statement with a  clause, that  clause is executed before REALLY leaving the function."

PhrontDoor
Автор

You do realize the finally block is supposed to be used to clean up work such as closing files. You are supposed to return the value in either the try and except part of the statement. The finally will run regardless of when the return happens. That's the point of it.

chrono
Автор

Instead of using finally here, you can use else, which means it only runs if no error happens.

Mathman
Автор

British people be like:
this pheechu ... 😂

thealex
Автор

"This feature recently broke my code in python". Did you just make this up or did you actually write this for some reason?

callbettersaul
Автор

So does this mean that the "return 0" statement just gets ignored? If the finally block just had a print("foo") instead of return, would it return 0?

scottcampbell
Автор

You have a gift for teaching. Truly remarkable!

MyCodingDiary
Автор

The feature didn’t break your code. Your code was already broken. The action of returning from a finally block is a code smell that is so widely known, that it is encoded in various linters such as Ruff, as SIM107. Such code checkers contain the accumulated wisdom of many developers, and the real lesson from this video would be to use them.

five-toedslothbear
Автор

Return statement should be forbiden in catch/finally block

igorfujs
Автор

now I understand this finally finally...👌👌👌

abdullahsaid
Автор

its called finally ... cant be anymore clearer than that.
its ment for use with context managers.
use else instead

KeithKazamaFlick
Автор

In most PL I believe finally is the last to execute. the weird thing is if you use return statement it should ended it right away.
The fact that it isn't mean there's something wrong.
In the language I'm using it won't allow you to use return on finally.

asagiai
Автор

I think you meant to use 'else' here instead of finally

BBCCheese
Автор

Do you return values from finally? Face the consequences

sergeibatiuk
Автор

Surely that must be a bug right? Because that’s not supposed to do that right? Shouldn’t the “finally” block be unreachable in that case?

astromec