<jupyter_start><jupyter_text>Try-rescue-catch-elseFrom the [Special Forms docs](https://hexdocs.pm/elixir/Kernel.SpecialForms.htmltry/1) `rescue`Rescue a single exception without binding the exception to a variable<jupyter_code>try do
  UndefinedModule.undefined_function
rescue
  UndefinedFunctionError -> nil
end<jupyter_output><empty_output><jupyter_text>---Rescue any of the given exception without binding<jupyter_code>try do
  UndefinedModule.undefined_function
rescue
  [UndefinedFunctionError, ArgumentError] -> nil
end<jupyter_output><empty_output><jupyter_text>---Rescue and bind the exception to the variable "x"<jupyter_code>try do
  UndefinedModule.undefined_function
rescue
  x in [UndefinedFunctionError] ->
    "somthing with #{inspect(x)}"
end<jupyter_output><empty_output><jupyter_text>---Rescue all kinds of exceptions and bind the rescued exception to the variable "x"<jupyter_code>try do
  UndefinedModule.undefined_function
rescue
  x -> "somthing else with #{inspect(x)}"
end<jupyter_output><empty_output><jupyter_text>---Erlang errors are transformed into Elixir errors when rescuing.<jupyter_code>try do
  :erlang.error(:badarg)
rescue
  ArgumentError -> :ok
end<jupyter_output><empty_output><jupyter_text>---The most common Erlang errors will be transformed into their Elixir counterpart. Those which are not will be transformed into the more generic `ErlangError`.<jupyter_code>try do
  :erlang.error(:unknown)
rescue
  ErlangError -> :ok
end<jupyter_output><empty_output><jupyter_text>`catch``catch` is used for thrown values...<jupyter_code>try do
  throw(:some_value)
catch
  thrown_value ->
    IO.puts("A value was thrown: #{inspect(thrown_value)}")
end<jupyter_output>A value was thrown: :some_value<jupyter_text>---and exits<jupyter_code>try do
  exit(:shutdown)
catch
  :exit, value ->
    IO.puts("Exited with value #{inspect(value)}")
end<jupyter_output>Exited with value :shutdown<jupyter_text>---And can match kind of value, and the value itself.<jupyter_code>try do
  exit(:shutdown)
catch
  kind, value when kind in [:exit, :throw] ->
    IO.puts("Caught #{inspect(kind)} with value #{inspect(value)}")
end
try do
  throw(:some_value)
catch
  kind, value when kind in [:exit, :throw] ->
    IO.puts("Caught #{inspect(kind)} with value #{inspect(value)}")
end<jupyter_output>Caught :throw with value :some_value<jupyter_text>`else``else` clases allow the result of the body passed to `try` to be pattern matched.<jupyter_code>x = 2
try do
  1 / 0
rescue
  ArithmeticError ->
    :infinity
else
  y when y < 1 and y > -1 ->
    :small
  _ ->
    :large
end<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11085714285714286, 'fraction_numerical': 0.002285714285714286, 'mean_word_length': 5.66497461928934, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 52, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '418278', 'license': 'MIT', 'n_tokens_mistral': 917, 'n_tokens_neox': 901, 'n_words': 231, 'path': '9) Pattern Matching - Try-rescue-catch-else-after.ipynb', 'repo_name': 'mudphone/EveryElixirPatternMatchingExampleEver', 'size': '2625'}