See how to handle predictable and recoverable errors at runtime by defining throwing functions. Learn how to create types to represent errors and catch and handle errors.
- [Instructor] Sometimes a function can encounter errors,…predictable and recoverable errors.…Swift enables you to write preemptive code…to handle these errors instead…of just having your app crash.…Functions that can encounter recoverable errors…are referred to as throwing functions,…and when they encounter such a problem they throw an error.…I'm starting out with a helper function…that returns a Boolean to simulate…if an error occurred, and I have two values…to hold the results of calling that function.…I'll define an enumeration to represent two errors,…including one that associates data with the error case.…If you're not familiar with enumerations,…I cover them in the types chapter.…
Error is a protocol, which essentially…is a contract that defines requirements.…However, in this case error is just…a declaration, there are no requirements.…Any custom type can be used to create an error type…simply by declaring adoption of that protocol.…So now I'll define a function perform action…that prints a message, and to indicate…
Learn how to write code, understand Swift's key concepts and best practices, and strengthen your programming problem-solving skills. Instructor Scott Gardner teaches the fundamentals, so you'll be prepared to develop applications for iOS, macOS, and other platforms. Completing this course will enable you to not only write first-class code, but to think like a Swift developer.
- Creating playgrounds
- Defining variables and constants
- Working with characters and strings
- Working with collections and groups
- Using operators and defining custom operators
- Controlling program flow
- Defining functions and closures
- Working with classes, structures, and enumerations
- Adopting protocols
Skill Level Beginner
1. Get Started
2. Variables and Constants
3. Characters and Strings
4. Collections and Tuples
6. Control Flow
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.