aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cErrors.ml41
-rw-r--r--lib/cErrors.mli13
-rw-r--r--lib/control.ml6
-rw-r--r--lib/flags.ml4
-rw-r--r--lib/future.ml6
-rw-r--r--lib/pp.ml2
6 files changed, 32 insertions, 40 deletions
diff --git a/lib/cErrors.ml b/lib/cErrors.ml
index b9735d0579..323dc8c1a4 100644
--- a/lib/cErrors.ml
+++ b/lib/cErrors.ml
@@ -12,7 +12,7 @@ open Pp
(** Aliases *)
-let push = Backtrace.add_backtrace
+let push = Exninfo.capture
(* Errors *)
@@ -51,12 +51,10 @@ let raw_anomaly e = match e with
| _ ->
str "Uncaught exception " ++ str (Printexc.to_string e) ++ str "."
-let print_backtrace e = match Backtrace.get_backtrace e with
+let print_backtrace e = match Exninfo.get_backtrace e with
| None -> mt ()
| Some bt ->
- let bt = Backtrace.repr bt in
- let pr_frame f = str (Backtrace.print_frame f) in
- let bt = prlist_with_sep fnl pr_frame bt in
+ let bt = str (Exninfo.backtrace_to_string bt) in
fnl () ++ hov 0 bt
let print_anomaly askreport e =
@@ -68,12 +66,10 @@ let print_anomaly askreport e =
let handle_stack = ref []
-exception Unhandled
-
let register_handler h = handle_stack := h::!handle_stack
let is_handled e =
- let is_handled_by h = (try let _ = h e in true with | Unhandled -> false) in
+ let is_handled_by h = Option.has_some (h e) in
List.exists is_handled_by !handle_stack
let is_anomaly = function
@@ -90,30 +86,31 @@ let register_additional_error_info (f : Exninfo.info -> (Pp.t option Loc.located
all the handlers of a list, and finally a [bottom] handler if all
others have failed *)
-let rec print_gen ~anomaly ~extra_msg stk (e, info) =
+let rec print_gen ~anomaly ~extra_msg stk e =
match stk with
| [] ->
print_anomaly anomaly e
| h::stk' ->
- try
- let err_msg = h e in
+ match h e with
+ | Some err_msg ->
Option.cata (fun msg -> msg ++ err_msg) err_msg extra_msg
- with
- | Unhandled -> print_gen ~anomaly ~extra_msg stk' (e,info)
- | any -> print_gen ~anomaly ~extra_msg stk' (any,info)
+ | None ->
+ print_gen ~anomaly ~extra_msg stk' e
let print_gen ~anomaly (e, info) =
let extra_info =
try CList.find_map (fun f -> Some (f info)) !additional_error_info_handler
with Not_found -> None
in
- let extra_msg, info = match extra_info with
- | None -> None, info
- | Some (loc, msg) ->
- let info = Option.cata (fun l -> Loc.add_loc info l) info loc in
- msg, info
+ let extra_msg = match extra_info with
+ | None -> None
+ | Some (loc, msg) -> msg
in
- print_gen ~anomaly ~extra_msg !handle_stack (e,info)
+ try
+ print_gen ~anomaly ~extra_msg !handle_stack e
+ with exn ->
+ (* exception in error printer *)
+ str "<in exception printer>" ++ fnl () ++ print_anomaly anomaly exn
(** The standard exception printer *)
let iprint (e, info) =
@@ -132,8 +129,8 @@ let print_no_report e = iprint_no_report (e, Exninfo.info e)
let _ = register_handler begin function
| UserError(s, pps) ->
- where s ++ pps
- | _ -> raise Unhandled
+ Some (where s ++ pps)
+ | _ -> None
end
(** Critical exceptions should not be caught and ignored by mistake
diff --git a/lib/cErrors.mli b/lib/cErrors.mli
index 02eaf6bd0b..1660a00244 100644
--- a/lib/cErrors.mli
+++ b/lib/cErrors.mli
@@ -46,19 +46,14 @@ exception Timeout
recent first) until a handle deals with it.
Handles signal that they don't deal with some exception
- by raising [Unhandled].
+ by returning None. Raising any other exception is
+ forbidden and will result in an anomaly.
- Handles can raise exceptions themselves, in which
- case, the exception is passed to the handles which
- were registered before.
-
- The exception that are considered anomalies should not be
+ Exceptions that are considered anomalies should not be
handled by registered handlers.
*)
-exception Unhandled
-
-val register_handler : (exn -> Pp.t) -> unit
+val register_handler : (exn -> Pp.t option) -> unit
(** The standard exception printer *)
val print : exn -> Pp.t
diff --git a/lib/control.ml b/lib/control.ml
index 7d54838df8..e67e88ee95 100644
--- a/lib/control.ml
+++ b/lib/control.ml
@@ -38,7 +38,7 @@ let unix_timeout n f x e =
restore_timeout ();
res
with e ->
- let e = Backtrace.add_backtrace e in
+ let e = Exninfo.capture e in
restore_timeout ();
Exninfo.iraise e
@@ -76,7 +76,7 @@ let windows_timeout n f x e =
else raise e
| e ->
let () = killed := true in
- let e = Backtrace.add_backtrace e in
+ let e = Exninfo.capture e in
Exninfo.iraise e
type timeout = { timeout : 'a 'b. int -> ('a -> 'b) -> 'a -> exn -> 'b }
@@ -102,7 +102,7 @@ let protect_sigalrm f x =
| true, Sys.Signal_handle f -> f Sys.sigalrm; res
| _, _ -> res
with e ->
- let e = Backtrace.add_backtrace e in
+ let e = Exninfo.capture e in
Sys.set_signal Sys.sigalrm old_handler;
Exninfo.iraise e
with Invalid_argument _ -> (* This happens on Windows, as handling SIGALRM does not seem supported *)
diff --git a/lib/flags.ml b/lib/flags.ml
index b87ba46634..ad48024761 100644
--- a/lib/flags.ml
+++ b/lib/flags.ml
@@ -19,7 +19,7 @@ let with_modified_ref ?(restore=true) r nf f x =
if restore || pre == !r then r := old_ref;
res
with reraise ->
- let reraise = Backtrace.add_backtrace reraise in
+ let reraise = Exninfo.capture reraise in
r := old_ref;
Exninfo.iraise reraise
@@ -37,7 +37,7 @@ let with_options ol f x =
let r = f x in
let () = List.iter2 (:=) ol vl in r
with reraise ->
- let reraise = Backtrace.add_backtrace reraise in
+ let reraise = Exninfo.capture reraise in
let () = List.iter2 (:=) ol vl in
Exninfo.iraise reraise
diff --git a/lib/future.ml b/lib/future.ml
index 5cccd2038d..ddf841b7fc 100644
--- a/lib/future.ml
+++ b/lib/future.ml
@@ -28,9 +28,9 @@ exception NotReady of string
exception NotHere of string
let _ = CErrors.register_handler (function
- | NotReady name -> !not_ready_msg name
- | NotHere name -> !not_here_msg name
- | _ -> raise CErrors.Unhandled)
+ | NotReady name -> Some (!not_ready_msg name)
+ | NotHere name -> Some (!not_here_msg name)
+ | _ -> None)
type fix_exn = Exninfo.iexn -> Exninfo.iexn
let id x = x
diff --git a/lib/pp.ml b/lib/pp.ml
index 3e9ab2a82b..1bd160dcda 100644
--- a/lib/pp.ml
+++ b/lib/pp.ml
@@ -203,7 +203,7 @@ let pp_with ft pp =
in
try pp_cmd pp
with reraise ->
- let reraise = Backtrace.add_backtrace reraise in
+ let reraise = Exninfo.capture reraise in
let () = Format.pp_print_flush ft () in
Exninfo.iraise reraise