Search
 
SCRIPT & CODE EXAMPLE
 

ELIXIR

elixir try catch

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
Comment

PREVIOUS NEXT
Code Example
Elixir :: elixir hello world 
Elixir :: HTTPoison post json 
Elixir :: what is elixir language 
Elixir :: phoenix run server 
Elixir :: elixir ecto pluck ids 
Elixir :: elixir check memory usage 
Elixir :: liveview component 
Elixir :: elixir nested if 
Scala :: else if scala 
Scala :: val in scala 
Scala :: scala home set up 
Scala :: scala check if seq container true booleans 
Actionscript :: mount_osxfuse : Input/output error 
Excel :: google sheets return multiple columns with vlookup 
Excel :: Time and date maths in Excel 
Perl :: read a file in perl 
Perl :: what happened to perl 6 
Pascal :: while do in pascal 
Powershell :: call function powershell 
Gdscript :: gdscript vector2 
Lisp :: lisp input 
Assembly :: custom color bootstrap buttonm 
Assembly :: html drag and drop anywhere 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: remove non letters from a string javascript 
Javascript :: window.reload 
Javascript :: javascript split and trim 
Javascript :: update node.js dependencies 
Javascript :: javascript to detect browser 
Javascript :: how to get element by title js 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =