diff options
author | Alain Frisch <alain@frisch.fr> | 2013-09-12 14:45:03 +0000 |
---|---|---|
committer | Alain Frisch <alain@frisch.fr> | 2013-09-12 14:45:03 +0000 |
commit | 884ca00fdfc1fe5f6165fbb847c6744a47fb59d2 (patch) | |
tree | bd64e49f3c3a449e41120b0e3508e120986ceab0 | |
parent | 8660e346df9c4b9bb5db38d5c91689f8a6ad906c (diff) | |
download | ocaml-884ca00fdfc1fe5f6165fbb847c6744a47fb59d2.tar.gz |
Continue cleanup. driver/errors.ml is no longer needed.
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/exception_registration@14120 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | driver/errors.ml | 17 | ||||
-rw-r--r-- | driver/main.ml | 2 | ||||
-rw-r--r-- | driver/opterrors.ml | 1 | ||||
-rw-r--r-- | ocamldoc/odoc_analyse.ml | 25 | ||||
-rw-r--r-- | parsing/location.ml | 6 | ||||
-rw-r--r-- | parsing/location.mli | 3 | ||||
-rw-r--r-- | tools/ocamlprof.ml | 19 | ||||
-rw-r--r-- | toplevel/toploop.ml | 4 | ||||
-rw-r--r-- | toplevel/topmain.ml | 2 |
9 files changed, 29 insertions, 50 deletions
diff --git a/driver/errors.ml b/driver/errors.ml index 4f8a4eb3e4..cb1a047ec6 100644 --- a/driver/errors.ml +++ b/driver/errors.ml @@ -10,19 +10,4 @@ (* *) (***********************************************************************) -(* WARNING: if you change something in this file, you must look at - opterrors.ml and ocamldoc/odoc_analyse.ml - to see if you need to make the same changes there. -*) - -open Format - -(* Report an error *) - -let report_error ppf exn = - let report ppf x = - match Location.error_of_exn x with - | Some err -> Location.report_error ppf err - | None -> fprintf ppf "@]"; raise x - in - fprintf ppf "@[%a@]@." report exn +let report_error = Location.report_exception diff --git a/driver/main.ml b/driver/main.ml index 4ab251c7f6..d038af75a5 100644 --- a/driver/main.ml +++ b/driver/main.ml @@ -184,7 +184,7 @@ let main () = end; exit 0 with x -> - Errors.report_error ppf x; + Location.report_exception ppf x; exit 2 let _ = main () diff --git a/driver/opterrors.ml b/driver/opterrors.ml index d516707db3..68279bff6e 100644 --- a/driver/opterrors.ml +++ b/driver/opterrors.ml @@ -40,5 +40,4 @@ let report_error ppf exn = | Some err -> Location.report_error ppf err | None -> fprintf ppf "@]"; raise x in - fprintf ppf "@[%a@]@." report exn diff --git a/ocamldoc/odoc_analyse.ml b/ocamldoc/odoc_analyse.ml index 7dd2e4456b..98f73617df 100644 --- a/ocamldoc/odoc_analyse.ml +++ b/ocamldoc/odoc_analyse.ml @@ -100,23 +100,16 @@ module Ast_analyser = Odoc_ast.Analyser (Odoc_comments.Basic_info_retriever) (** The module used to analyse the parse tree and typed tree of an interface file.*) module Sig_analyser = Odoc_sig.Analyser (Odoc_comments.Basic_info_retriever) -(** Handle an error. This is a partial copy of the compiler - driver/error.ml file. We do this because there are - some differences between the possibly raised exceptions - in the bytecode (error.ml) and opt (opterros.ml) compilers - and we don't want to take care of this. Besises, these - differences only concern code generation (i believe).*) +(** Handle an error. *) + let process_error exn = - let report ppf x = - match Location.error_of_exn x with - | Some err -> Location.report_error ppf err - | None -> - fprintf ppf "@]"; - fprintf ppf - "Compilation error(%s). Use the OCaml compiler to get more details." - (Printexc.to_string x) - in - Format.fprintf Format.err_formatter "@[%a@]@." report exn + match Location.error_of_exn exn with + | Some err -> + fprintf Format.err_formatter "@[%a@]@." Location.report_error err + | None -> + fprintf Format.err_formatter + "Compilation error(%s). Use the OCaml compiler to get more details.@." + (Printexc.to_string exn) (** Process the given file, according to its extension. Return the Module.t created, if any.*) let process_file ppf sourcefile = diff --git a/parsing/location.ml b/parsing/location.ml index 579c1dbefb..132021f5b9 100644 --- a/parsing/location.ml +++ b/parsing/location.ml @@ -360,3 +360,9 @@ let () = | _ -> None ) + + +let report_exception ppf exn = + match error_of_exn exn with + | Some err -> fprintf ppf "@[%a@]@." report_error err + | None -> raise exn diff --git a/parsing/location.mli b/parsing/location.mli index a2057442f9..e6df9d1f6c 100644 --- a/parsing/location.mli +++ b/parsing/location.mli @@ -106,3 +106,6 @@ val register_error_of_exn: (exn -> error option) -> unit being located as well). *) val report_error: formatter -> error -> unit + +val report_exception: formatter -> exn -> unit + (* Reraise the exception if it is unknown. *) diff --git a/tools/ocamlprof.ml b/tools/ocamlprof.ml index bb6d5086d4..1fde3fe495 100644 --- a/tools/ocamlprof.ml +++ b/tools/ocamlprof.ml @@ -499,18 +499,11 @@ let main () = " Print version number and exit"; ] process_anon_file usage; exit 0 - with x -> - let report_error ppf = function - | Profiler msg -> - fprintf ppf "@[%s@]@." msg - | Sys_error msg -> - fprintf ppf "@[I/O error:@ %s@]@." msg - | x -> - match Location.error_of_exn x with - | Some err -> fprintf ppf "@[%a@]@." Location.report_error err - | None -> raise x - in - report_error Format.err_formatter x; - exit 2 + with + | Profiler msg -> + fprintf Format.err_formatter "@[%s@]@." msg; + exit 2 + | exn -> + Location.report_exception Format.err_formatter exn let _ = main () diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml index 8b8c659bd1..78c6eca32f 100644 --- a/toplevel/toploop.ml +++ b/toplevel/toploop.ml @@ -349,7 +349,7 @@ let use_file ppf wrap_mod name = with | Exit -> false | Sys.Break -> fprintf ppf "Interrupted.@."; false - | x -> Errors.report_error ppf x; false) in + | x -> Location.report_exception ppf x; false) in if must_close then close_in ic; success with Not_found -> fprintf ppf "Cannot find file %s.@." name; false @@ -468,7 +468,7 @@ let loop ppf = | End_of_file -> exit 0 | Sys.Break -> fprintf ppf "Interrupted.@."; Btype.backtrack snap | PPerror -> () - | x -> Errors.report_error ppf x; Btype.backtrack snap + | x -> Location.report_exception ppf x; Btype.backtrack snap done (* Execute a script. If [name] is "", read the script from stdin. *) diff --git a/toplevel/topmain.ml b/toplevel/topmain.ml index 8fbf9ddc5c..3091ca0d2a 100644 --- a/toplevel/topmain.ml +++ b/toplevel/topmain.ml @@ -26,7 +26,7 @@ let prepare ppf = !Toploop.toplevel_startup_hook (); res with x -> - try Errors.report_error ppf x; false + try Location.report_exception ppf x; false with x -> Format.fprintf ppf "Uncaught exception: %s\n" (Printexc.to_string x); false |