June 2017
Beginner
352 pages
8h 39m
English
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 convertTraceback (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 ...
Read now
Unlock full access