anchor.diff:  	end.
   
   if_none_match(Req, State, EtagsList) ->
  -	{Etag, Req2, State2} = generate_etag(Req, State),
  -	case Etag of
  -		undefined ->
  -			precondition_failed(Req2, State2);
  -		Etag ->
  -			case lists:member(Etag, EtagsList) of
  -				true -> precondition_is_head_get(Req2, State2);
  -				false -> if_modified_since_exists(Req2, State2)
  +	try generate_etag(Req, State) of
  +		{Etag, Req2, State2} ->
  +			case Etag of
  +				undefined ->
  +					precondition_failed(Req2, State2);
  +				Etag ->
  +					case lists:member(Etag, EtagsList) of
  +						true -> precondition_is_head_get(Req2, State2);
  +						false -> if_modified_since_exists(Req2, State2)
  +					end
   			end
  +	catch Class:Reason ->
  +		error_logger:error_msg(
  +			"** Cowboy handler ~p terminating in ~p/~p~n"
  +			"   for the reason ~p:~p~n** Handler state was ~p~n"
  +			"** Request was ~p~n** Stacktrace: ~p~n~n",
  +			[State#state.handler, generate_etag, 2,
  +				Class, Reason, State#state.handler_state,
  +				cowboy_req:to_list(Req), erlang:get_stacktrace()]),
  +		error_terminate(Req, State)
   	end.
   
   precondition_is_head_get(Req, State=#state{method=Method})
  
positive.code: 	end.
  
  if_match(Req, State, EtagsList) ->
  	{Etag, Req2, State2} = generate_etag(Req, State),
  	case lists:member(Etag, EtagsList) of
  		true -> if_unmodified_since_exists(Req2, State2);
  		%% Etag may be `undefined' which cannot be a member.
  		false -> precondition_failed(Req2, State2)
  	end.
  
  if_match_must_not_exist(Req, State) ->
  
negative.code: 	{ok, Req2} = cowboy_req:reply(StatusCode, Req),
  	terminate(Req2, State).
  
  terminate(Req, State=#state{env=Env}) ->
  	rest_terminate(Req, State),
  	{ok, Req, [{result, ok}|Env]}.
  
  -spec error_terminate(cowboy_req:req(), #state{}) -> no_return().
  error_terminate(Req, State) ->
  	rest_terminate(Req, State),
  	erlang:throw({?MODULE, error}).
  
  rest_terminate(Req, #state{handler=Handler, handler_state=HandlerState}) ->
  	case erlang:function_exported(Handler, rest_terminate, 2) of
  		true -> ok = Handler:rest_terminate(
  			cowboy_req:lock(Req), HandlerState);
  		false -> ok
  	end.
  