Back to questions
JuniorTheoryCommon
What does the program print?
try:
int("ten")
except Exception:
print("general")
except ValueError:
print("value")general
- Expecting
value, as if Python picked the most specificexcept: it checks them top to bottom and runs the first that matches, andValueErroris a kind ofException. - Expecting a
SyntaxErrorfor the unreachableexcept ValueError: Python accepts it, but the branch never runs because the one above always catches first.
- How would you reorder the branches so that
valueis printed? - Which
exceptruns forint(None), and why?