Introduction
Heads up... You’re accessing parts of this content for free, with some sections shown as
text.
Heads up... You’re accessing parts of this content for free, with some sections shown as
text.Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
Unlock now
In the previous lesson, you saw that defining a function that throws
doesn’t enable the compiler to provide as much coding assistance as you’d like.
- To
switch
over the cases of a specificError
type, you must casterror
as that type. - Or, you must specify the type of
Error
for eachcatch
closure, even if the throwing function throws only one type ofError
. - And you must always catch any other errors, even when you know the throwing functions never throw any other type of
Error
.
Learning Objectives
In this lesson, you’ll see how typed throws overcome these issues, to help the compiler help you. You’ll learn: