40 Error handling with Try
After reading this lesson, you will be able to
- Represent a computation that can fail using
Try
- Decompose it using pattern matching
- Manipulate its value using the
map
,flatten
, andflatMap
operations - Chain several
Try
instances usingfor-comprehension
- Check if a computation has failed and retrieve its value
In the previous lessons, you mastered the type Either
. In this lesson, you’ll learn about the class Try
to represent a computation that can fail. Throwing exceptions is a risky and unpredictable practice. Knowing which exceptions a method may throw is challenging, if not impossible, as they are often not annotated and are highly dependent on the specifics of their implementation. The class Try
allows you to control ...
Get Get Programming with Scala now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.