title: try rescue does not does not catch an error
body: <pre><code>  def page_request(url, proxy) do
      uri = URI.parse(proxy)
      case uri.host do
        nil -&gt; raise "Host nil! #{proxy}"
        _ -&gt;
          options =
          case uri.scheme do
              "socks5" -&gt; default_params() ++ [proxy: {:socks5, String.to_charlist(uri.host), uri.port}]
              _-&gt; default_params() ++ [proxy: String.to_charlist(proxy)]
          end
          try do #36 line!
            case HTTPoison.request(:get, String.to_charlist(url), "", [], options) do
              {:ok, response} -&gt;
                %HTTPoison.Response{headers: header, body: body} = response
                gzipped = Enum.any?(header, fn (kv) -&gt;
                  case kv do
                    {"Content-Encoding", "gzip"} -&gt; true
                    {"Content-Encoding", "x-gzip"} -&gt; true
                    _ -&gt; false
                  end
                end)
                case body do
                  nil -&gt; {:ok, %{}}
                  _ -&gt;
                    if gzipped do
                      {:ok, :zlib.gunzip(body)}
                    else
                      {:ok, body}
                    end
                end
              {:error, reason} -&gt;
                {:error, reason}
            end
          rescue
            error -&gt; {:error, error}
          end
      end
    end
  </code></pre>
  
  <p>I can not understand why <code>try..rescue</code> does not catch an error?</p>
  
  <pre><code>15:34:24.537 [error] GenServer MyWeb.Worker1 terminating
  ** (ArgumentError) argument error
      (kernel) gen_tcp.erl:150: :gen_tcp.connect/4
      (hackney) /home/book/my_web/deps/hackney/src/hackney_connect.erl:247: :hackney_connect.do_connect/5
      (hackney) /home/book/my_web/deps/hackney/src/hackney.erl:354: :hackney.send_request/2
      (hackney) /home/book/my_web/deps/hackney/src/hackney.erl:810: :hackney.redirect/2
      (hackney) /home/book/my_web/deps/hackney/src/hackney.erl:742: :hackney.maybe_redirect1/3
      (hackney) /home/book/my_web/deps/hackney/src/hackney.erl:362: :hackney.send_request/2
      (httpoison) lib/httpoison/base.ex:439: HTTPoison.Base.request/9
      (my_web) lib/my_web.ex:37: MyWeb.page_request/2
  Last message: :work
  State: nil
  </code></pre>
  
  <p>I thought this code should catch any error</p>
  
  <p>but in iex works:</p>
  
  <p>Interactive Elixir (1.6.0) - press Ctrl+C to exit (type h() ENTER for help)</p>
  
  <pre><code>iex(1)&gt; try do
  ...(1)&gt; raise ArgumentError
  ...(1)&gt; rescue
  ...(1)&gt; error -&gt; {:error, error}
  ...(1)&gt; end
  {:error, %ArgumentError{message: "argument error"}}
  </code></pre>
  
  <p>I looked through the <a href="https://elixir-lang.org/getting-started/try-catch-and-rescue.html" rel="nofollow noreferrer">documentation</a>, but could not find the answer</p>
  
  <p>elixir 1.6.1</p>
  
  <p>example url <a href="http://google.com" rel="nofollow noreferrer">http://google.com</a></p>
  
  <pre><code>  defp default_params(timeout \\ 25) do
        [ssl: [verify: :verify_none],
        timeout: timeout*1000,
        recv_timeout: timeout*1000,
        connect_timeout: timeout*1000,
        follow_redirect: true,
        hackney: [pool: false, insecure: true]]
    end
  </code></pre>