Now that we're confident with the control flow for exception behavior, we can remove the print statements:
def convert(s):
"""Convert a string to an integer."""
x = -1
try:
x = int(s)
except (ValueError, TypeError):
return x
But now when we try to import our program:
>>> from exceptional import convert
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "./exceptional.py", line 11
return x
^
IndentationError: expected an indented block
we get yet another type of exception, an IndentationError, because our except block is now empty and empty blocks are not permitted in Python programs.
This is not an exception type that is ever useful to catch with an except block! Almost anything that goes wrong with a Python program results in...