Elixir Try Catch

[Solved] Elixir Try Catch | Elixir - Code Explorer | yomemimo.com
Question : elixir catch

Answered by : nasty-nightingale-6kbfxg59j1af

defmodule SomeModule do @doc """ iex> SomeModule.do_something() {:error, "error: %ArgumentError{message: \\"You provided a wrong argument\\"}"} """ def do_something() do raise ArgumentError, "You provided a wrong argument" catch kind, error -> {:error, "#{kind}: #{inspect(error)}"} end @doc """ iex> SomeModule.try_something() {:error, "error: %ArgumentError{message: \\"You provided a wrong argument\\"}"} """ def try_something() do try do raise ArgumentError, "You provided a wrong argument" catch kind, error -> {:error, "#{kind}: #{inspect(error)}"} end end
end

Source : https://elixir-lang.org/getting-started/try-catch-and-rescue.html | Last Update : Sun, 22 May 22

Answers related to elixir try catch

Code Explorer Popular Question For Elixir