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 switch over the cases of a specific Error type, you must cast error as that type.
  • Or, you must specify the type of Error for each catch closure, even if the throwing function throws only one type of Error.
  • 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.
See forum comments
Download course materials from Github
Previous: Conclusion Next: Typed Throws