Chapter 9. Error Handling
In an ideal world, you write a program and it runs perfectly on every computer for every user and in every situation. The real world is different, however, and throws curve balls at every opportunity. Your programs are afflicted with errors you never even dreamed of. Perhaps the user types in an unexpected answer. Or you get back an empty list (which, of course, is never supposed to be empty), and then you try to access items from the list. Or maybe you try to write to a file, and you don't have the correct permissions to do so. These types of events often generate errors that cause your program to terminate. Predicting these types of errors and handling them gracefully is one of the keys to being a good programmer. It is also the subject of this chapter.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access