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 join list of strings 
Elixir :: elixir get_in 
Elixir :: hello world in elixir 
Elixir :: elixir enum each 
Elixir :: phoenix enum filter 
Elixir :: elixir format code 
Elixir :: phoenix ecto query bindingess 
Elixir :: elixir alias multiple module 
Scala :: array in scala 
Scala :: scala 
Scala :: how to get absolute value in scala 
Scala :: how to tell what type a variable is scala 
Actionscript :: docker compose enable rabbitmq enable plugins 
Excel :: google sheets countif current month 
Excel :: add drop down in excel 
Perl :: perl for loop 
Perl :: Perl - Common Conditional Statements 
Pascal :: pascal loop 
Powershell :: How to display firewall rule ports with powershell 
Gdscript :: godot yield idle frame 
Lisp :: common lisp ide macos 
Assembly :: havong space between lines of richtext in flutter 
Assembly :: assembly language display message 
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
1+6 =