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.

Get Beginning AppleScript® 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.