Chapter 18. Adding Code to Handle Errors

Hour 17, “Removing Bugs,” taught you how to hunt down, find, and remove bugs in your program. This hour will teach you how to handle the errors in your program that aren’t bugs. It’s important to understand this distinction: Bugs are problems in the code, such as syntax errors, that interrupt execution of the code or produce incorrect results. On the other hand, if a user enters an invalid date into your program, that constitutes a user error. User errors are not the same as bugs. Users make mistakes, and you need to gently encourage them to do better, or, compensate so your users will not have to try so hard.

Other kinds of errors occur when a user tries to open a file that was deleted, when your program ...

Get Sams Teach Yourself Microsoft now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.