Permalink
Browse files

Avoid bad error report when a registered toplevel primitive raises No…

…t_found.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14671 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
1 parent df68e91 commit 3775a101e664f8c6fdf8bcb60256f021b42613a7 @alainfrisch alainfrisch committed Apr 23, 2014
Showing with 22 additions and 14 deletions.
  1. +22 −14 toplevel/toploop.ml
View
@@ -281,20 +281,28 @@ let execute_phrase print_outcome ppf phr =
toplevel_env := oldenv; raise x
end
| Ptop_dir(dir_name, dir_arg) ->
- try
- match (Hashtbl.find directive_table dir_name, dir_arg) with
- | (Directive_none f, []) -> f (); true
- | (Directive_string f, [Pdir_string s]) -> f s; true
- | (Directive_int f, [Pdir_int n]) -> f n; true
- | (Directive_ident f, [Pdir_ident lid]) -> f lid; true
- | (Directive_bool f, [Pdir_bool b]) -> f b; true
- | (Directive_generic f, l) -> f l; true
- | (_, _) ->
- fprintf ppf "Wrong type of argument for directive `%s'.@." dir_name;
- false
- with Not_found ->
- fprintf ppf "Unknown directive `%s'.@." dir_name;
- false
+ let d =
+ try Some (Hashtbl.find directive_table dir_name)
+ with Not_found -> None
+ in
+ begin match d with
+ | None ->
+ fprintf ppf "Unknown directive `%s'.@." dir_name;
+ false
+ | Some d ->
+ match d, dir_arg with
+ | Directive_none f, [] -> f (); true
+ | Directive_string f, [Pdir_string s] -> f s; true
+ | Directive_int f, [Pdir_int n] -> f n; true
+ | Directive_ident f, [Pdir_ident lid] -> f lid; true
+ | Directive_bool f, [Pdir_bool b] -> f b; true
+ | Directive_generic f, l -> f l; true
+ | _ ->
+ fprintf ppf "Wrong type of argument for directive `%s'.@."
+ dir_name;
+ false
+ end
+
(* Temporary assignment to a reference *)

0 comments on commit 3775a10

Please sign in to comment.