Tracks
/
Elixir
Elixir
/
Syllabus
/
Try/Rescue/Else/After
Tr

Try/Rescue/Else/After in Elixir

1 exercise

About Try/Rescue/Else/After

The basic try .. rescue concept can be extended to support else and after clauses:

  • The else block:
    • Where a pattern match on the successful result from the try-block occurs.
  • The after block:
    • Where functions are invoked whether the try-block succeeds or is rescued as long as the program is running.
    • The result of the after block is not returned to the calling scope.
try do
  :a
rescue
  _ -> :error
else
  :a -> :success
after
  :some_action
end

# => :success
Edit via GitHub The link opens in a new window or tab