Skip to content

Commit

Permalink
Allow formatting in try-rescue snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Jun 17, 2024
1 parent bbef98e commit 48ccb7c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
10 changes: 4 additions & 6 deletions concepts/try-rescue/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@

For example:

[//]: # (elixir-formatter-disable-next-block)

```elixir
try do #1
raise RuntimeError, "error" #2
try do
raise RuntimeError, "error"
rescue
e in RuntimeError -> :error #3
e in RuntimeError -> :error
end
```

- **Line 1**, the block is declared with `try`.
- **Line 2**, the function call which may generate an error is placed here, in this case we are calling `raise/1`.
- **Line 3**, in the `rescue` section, we pattern match on the _Module_ name of the error raised
- **Line 4**, in the `rescue` section, we pattern match on the _Module_ name of the error raised
- on the left side of `->`:
- `e` is matched to the error struct.
- `in` is a keyword.
Expand Down
10 changes: 4 additions & 6 deletions concepts/try-rescue/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

Elixir provides a construct for rescuing from errors using `try .. rescue`

[//]: # (elixir-formatter-disable-next-block)

```elixir
try do #1
raise RuntimeError, "error" #2
try do
raise RuntimeError, "error"
rescue
e in RuntimeError -> :error #3
e in RuntimeError -> :error
end
```

Let's examine this construct:

- **Line 1**, the block is declared with `try`.
- **Line 2**, the function call which may error is placed here, in this case we are calling `raise/2`.
- **Line 3**, in the `rescue` section, we pattern match on the _Module_ name of the error raised
- **Line 4**, in the `rescue` section, we pattern match on the _Module_ name of the error raised
- on the left side of `->`:
- `e` is matched to the error struct.
- `in` is a keyword.
Expand Down
10 changes: 4 additions & 6 deletions exercises/concept/rpn-calculator/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ Map.fetch!(%{a: 1}, :b)

Elixir provides a construct for rescuing from errors using `try .. rescue`

[//]: # (elixir-formatter-disable-next-block)

```elixir
try do #1
raise RuntimeError, "error" #2
try do
raise RuntimeError, "error"
rescue
e in RuntimeError -> :error #3
e in RuntimeError -> :error
end
```

Let's examine this construct:

- **Line 1**, the block is declared with `try`.
- **Line 2**, the function call which may error is placed here, in this case we are calling `raise/2`.
- **Line 3**, in the `rescue` section, we pattern match on the _Module_ name of the error raised
- **Line 4**, in the `rescue` section, we pattern match on the _Module_ name of the error raised
- on the left side of `->`:
- `e` is matched to the error struct.
- `in` is a keyword.
Expand Down

0 comments on commit 48ccb7c

Please sign in to comment.