Elixir try rescue

Code examples

2
0

elixir try rescue

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

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

Similar pages

Similar pages with examples

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................