Skip to content

Commit 28926a9

Browse files
committed
chore: touch up error handling for modern Python
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 4ccb50d commit 28926a9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

_episodes/09-errors.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ as it is possible to create custom errors.
127127
In that case,
128128
hopefully the custom error message is informative enough to help you figure out what went wrong.
129129

130+
> ## Better errors on newer Pythons
131+
>
132+
> Newer versions of Python have improved error printouts. If you are debugging errors, it is often
133+
> helpful to use the latest Python version, even if you support older versions of Python.
134+
{: .callout}
135+
130136
## Syntax Errors
131137

132138
When you forget a colon at the end of a line,
@@ -373,7 +379,9 @@ you will receive a `FileNotFoundError` telling you so.
373379
If you attempt to write to a file that was opened read-only, Python 3
374380
returns an `UnsupportedOperationError`.
375381
More generally, problems with input and output manifest as
376-
`IOError`s or `OSError`s, depending on the version of Python you use.
382+
`OSError`s, which may show up as a more specific subclass; you can see
383+
[the list in the Python docs](https://docs.python.org/3/library/exceptions.html#os-exceptions).
384+
They all have a unique UNIX `errno`, which is you can see in the error message.
377385
378386
~~~
379387
file_handle = open('myfile.txt', 'r')

_episodes/10-defensive.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ This violates another important rule of programming:
534534
> > * The first assertion checks that the input sequence `values` is not empty.
535535
> > An empty sequence such as `[]` will make it fail.
536536
> > * The second assertion checks that each value in the list can be turned into an integer.
537-
> > Input such as `[1, 2,'c', 3]` will make it fail.
537+
> > Input such as `[1, 2, 'c', 3]` will make it fail.
538538
> > * The third assertion checks that the total of the list is greater than 0.
539539
> > Input such as `[-10, 2, 3]` will make it fail.
540540
> {: .solution}

0 commit comments

Comments
 (0)