Skip to content

Fix description of Failure #1835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _overviews/scala-book/functional-error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ These approaches were discussed in the “No Null Values” lesson, so we won’
Another trio of classes named `Try`, `Success`, and `Failure` work just like `Option`, `Some`, and `None`, but with two nice features:

- `Try` makes it very simple to catch exceptions
- `Failure` contains the exception message
- `Failure` contains the exception

Here’s the `toInt` method re-written to use these classes. First, import the classes into the current scope:

Expand Down Expand Up @@ -93,7 +93,7 @@ scala> val b = toInt("boo")
b: scala.util.Try[Int] = Failure(java.lang.NumberFormatException: For input string: "boo")
```

As that output shows, the `Failure` that’s returned by `toInt` contains the reason for the failure, i.e., the exception message.
As that output shows, the `Failure` that’s returned by `toInt` contains the reason for the failure, i.e., the exception.

There are quite a few ways to work with the results of a `Try` — including the ability to “recover” from the failure — but common approaches still involve using `match` and `for` expressions:

Expand Down