Try...Except
Exceptions report failures that a caller may need to handle. Catch the specific failure you expect and keep the protected operation small enough that the handler is unambiguous.
Understand the idea
A ValueError from int can become a helpful input message. An unrelated error should not silently turn into the same fallback. else can handle the successful path, and finally performs cleanup regardless of success. Context managers are usually clearer for ordinary file and resource cleanup.
Where to try it
Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.
A worked example
text = "three"
try:
quantity = int(text)
except ValueError:
print("Enter a whole number")
else:
print(quantity * 450)
Read the result
The example prints Enter a whole number rather than terminating with an uncaught conversion error.
Try one change
Test valid integer text, blank input, and decimal text, recording which path should run.