Wouldn't using after screw up the calling code? It looks like it expects Db
to be open in the happy case [1]. I might me missing something though.

[1]
https://github.com/cloudant/couch_replicator/blob/master/src/couch_replicator_utils.erl#L115L140
On 18 Jan 2014 03:34, "Adam Kocoloski" <notifications@github.com> wrote:

> In src/couch_replicator_api_wrap.erl:
>
> > +                    throw({unauthorized, ?l2b(db_uri(Db))});
> > +                (_, _, _) ->
> > +                    ok
> > +                end)
> > +        end,
> > +        send_req(Db, [{method, head}],
> > +            fun(200, _, _) ->
> > +                {ok, Db};
> > +            (401, _, _) ->
> > +                throw({unauthorized, ?l2b(db_uri(Db))});
> > +            (_, _, _) ->
> > +                throw({db_not_found, ?l2b(db_uri(Db))})
> > +            end)
> > +    catch _Tag:Error ->
> > +        db_close(Db),
> > +        throw(Error)
>
> You don't need to catch at all here. As @davisp<https://github.com/davisp>said use an
> after clause to close the Db without modifying the exception:
>
> try
>     ...
> after
>     db_close(Db)
> end
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/cloudant/couch_replicator/pull/48/files#r8986295>
> .
>