© Yanis Zafirópulos 2019
Yanis ZafirópulosSwift 4 Recipeshttps://doi.org/10.1007/978-1-4842-4182-0_11

11. Exceptions

Yanis Zafirópulos1 
(1)
Granada, Spain
 

Execution-time errors – or, in programming, Exceptions – are a rather normal, even though unpleasant, thing of every coder’s life. However, they can be prevented – or at least, at times. This is where Error Handling comes into play.

Error handling is nothing but a fancy name to describe the process of responding to the occurrence, during computation, of exceptions – anomalous conditions, that is, that may require some special processing. And Swift sure makes our life a lot easier.

11.1 Create a custom error

Problem

I want to create a new custom error type.

Solution

Let’s create our custom error type. ...

Get Swift 4 Recipes: Hundreds of Useful Hand-picked Code Snippets 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.