What are the different ways to handle errors thrown by a function in Swift?

Question

Grade: Education Subject: Support
What are the different ways to handle errors thrown by a function in Swift?
Asked by:
75 Viewed 75 Answers

Answer (75)

Best Answer
(228)
There are three main ways: 1. Propagate the error using 'throws'. 2. Use 'try?' to convert the error into an optional nil value. 3. Use 'try!' to assert that the function will not throw an error, crashing the program if it does.