Skip to content

Commit

Permalink
Added the '$catch' function in the README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rcardin committed Apr 15, 2024
1 parent 35d5a3f commit b015ab6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ Please be aware that any exception thrown inside the `Raise[E]` context will bub
def findUserByIdWithEx(id: String): User =
if (id == "42") User(id) else throw new IllegalArgumentException(s"User not found with id: $id")

either {
$catch[User](() => findUserByIdWithEx("42"), {
case _: IllegalArgumentException => raise(UserNotFound("42"))
})
}
val maybeUser: Either[Error, User] =
either:
$catch[User](() => findUserByIdWithEx("42"), {
case _: IllegalArgumentException => raise(UserNotFound("42"))
})
```

We will see the `either` function in a moment. As we can see, there’s nothing special with the `$catch` function. It just catches the exception and calls the catch lambda with the exception. The `$catch` function lets the fatal exception bubble up.
Expand Down

0 comments on commit b015ab6

Please sign in to comment.