O'Reilly logo

Learn Swift 2 on the Mac, Second Edition by Waqar Malik

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter    16

Error Handling

What is error handling? It is a process of properly handling unusual conditions in the program. There is an old saying: Garbage in, garbage out. Computers are machines that are very good at processing commands without questioning the input that is given to it. So if you give them bad data (garbage data), they will process it and give you bad results (garbage out). So it is the programmer’s responsibility to put guards against invalid or erroneous situations. Swift provides first-class support for handling these situations.

Let’s take a situation of downloading data from a remote server. If everything went correct, you would have data and then you could process it, but there can be various errors:

  • Network not reachable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required