Swift is designed to encourage safe, easy-to-read code, and its error-handling system is no different.
Any function that could fail must be marked with
This makes it obvious from the type of a function whether you need to handle potential errors.
Swift also requires you to mark all calls to functions that might fail with
This gives a great benefit to anyone reading Swift code.
If a function call is annotated with
try, you know it is a potential source of errors that must be handled.
If a function call is not annotated with
try, you know it will never emit errors that you need to handle.
If you have used C++ or Java, it is important to note the differences between Swift error handling and ...