in
     try
       coerce_to_something_aux t infty expty subst metasenv context ugraph
-    with Uncertain _ | RefineFailure _ ->
-      let exn = 
-        RefineFailure (lazy ("The term " ^
+    with Uncertain _ | RefineFailure _ as exn ->
+      let f _ =
+        lazy ("The term " ^
           CicMetaSubst.ppterm_in_context metasenv subst t context ^ 
           " has type " ^ CicMetaSubst.ppterm_in_context metasenv subst
           infty context ^ " but is here used with type " ^ 
-          CicMetaSubst.ppterm_in_context metasenv subst expty context))
+          CicMetaSubst.ppterm_in_context metasenv subst expty context)
       in
-        enrich localization_tbl t exn
+        enrich localization_tbl ~f t exn
 
   and coerce_to_sort localization_tbl t infty subst context metasenv uragph =
     match CicReduction.whd ~subst:subst context infty with