Created
June 21, 2019 16:04
-
-
Save koolquark/bbc4c6557ca5552dc2fe95c1e0a2083e to your computer and use it in GitHub Desktop.
Elixir - try catch throw example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Excep do | |
def ex() do | |
try do | |
throw("a") | |
catch | |
c -> | |
IO.inspect c # "a" | |
end | |
end | |
end | |
Excep.ex() | |
defmodule Excep do | |
def ex() do | |
try do | |
1/0 | |
catch | |
c -> | |
IO.inspect c # :badarith | |
end | |
end | |
end | |
Excep.ex() | |
defmodule Excep do | |
def ex() do | |
try do | |
1/0 | |
catch | |
e,r -> | |
IO.inspect e # :error | |
IO.inspect r # :badarith | |
end | |
end | |
end | |
Excep.ex() | |
defmodule Excep do | |
def ex(v) do | |
try do | |
throw(v) | |
1/v | |
catch | |
e,r -> | |
IO.inspect e # :throw | |
IO.inspect r # 8 | |
end | |
end | |
end | |
Excep.ex(8) | |
defmodule Excep do | |
def ex(v) do | |
try do | |
throw(v) | |
1/v | |
catch | |
c -> | |
IO.inspect c # 8 | |
end | |
end | |
end | |
Excep.ex(8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment