Introduction
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
switchover the cases of a specificErrortype, you must casterroras that type. - Or, you must specify the type of
Errorfor eachcatchclosure, 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:
- How to use typed throws.
- Possible problems with typed throws.