" but is here used with type " ^
              CicMetaSubst.ppterm_in_context ~metasenv [] ty' [])
           in
-           match exn with
-              RefineFailure _ -> raise (HExtlib.Localized (loc exn,RefineFailure msg))
-            | Uncertain _ -> raise (HExtlib.Localized (loc exn,Uncertain msg))
-            | _ -> assert false
+           let exn' =
+            match exn with
+               RefineFailure _ -> RefineFailure msg
+             | Uncertain _ -> Uncertain msg
+             | _ -> assert false
+           in
+            raise (HExtlib.Localized (loc exn',exn'))
      in
      let bo' = CicMetaSubst.apply_subst subst bo' in
      let ty' = CicMetaSubst.apply_subst subst ty' in