title: How to handle try and rescue errors in Elixir
body: <p>I am using try and rescue, but it's not working. When I do this,</p>
  <pre><code>iex(3)&gt; try do
  ...(3)&gt;   File.read! &quot;junaid&quot;
  ...(3)&gt; rescue
  ...(3)&gt;   error -&gt;
  ...(3)&gt;     IO.inspect error
  ...(3)&gt; end
  %File.Error{action: &quot;read file&quot;, path: &quot;junaid&quot;, reason: :enoent}
  %File.Error{action: &quot;read file&quot;, path: &quot;junaid&quot;, reason: :enoent}
  </code></pre>
  <p>but when I use it with my own method such as</p>
  <pre><code>iex(2)&gt; try do                                                     
  ...(2)&gt;   EvercamMedia.S3.do_save_multiple(%{&quot;junaid&quot; =&gt; &quot;junaid&quot;})
  ...(2)&gt; rescue                                                     
  ...(2)&gt;    error -&gt;                                                
  ...(2)&gt;      IO.inspect error                                      
  ...(2)&gt; end
  </code></pre>
  <p>but it won't work and give me such error</p>
  <pre><code>[error] Task #PID&lt;0.1075.0&gt; started from #PID&lt;0.1065.0&gt; terminating
  ** (File.Error) could not read file &quot;junaid&quot;: no such file or directory
      (elixir 1.11.1) lib/file.ex:354: File.read!/1
      (evercam_media 1.0.1607441172) lib/evercam_media/s3.ex:46: anonymous fn/1 in EvercamMedia.S3.do_save_multiple/1
  </code></pre>
  <p>Is it possible to just bypass this error and <code>do_something()</code> in rescue? or in any other clause which says, it's an error? instead of breaking the process?</p>
  <p>Why try and rescue don't work in such a way where it will do the work in try and if there is ANY error it will just go to the rescue and don't break the process.</p>
  <p>UPDATE: the method, <code>EvercamMedia.S3.do_save_multiple</code></p>
  <pre><code>  def do_save_multiple(paths) do
      upload_file = fn {src_path, dest_path} -&gt;
        ExAws.S3.put_object(&quot;evercam-camera-assets&quot;, dest_path, File.read!(src_path),
          acl: :public_read
        )
        |&gt; ExAws.request!()
      end
  
      paths
      |&gt; Task.async_stream(upload_file, max_concurrency: 10, timeout: :infinity)
      |&gt; Stream.run()
    end
  </code></pre>