@@ -711,17 +711,19 @@ end
711711open Basic_helpers
712712
713713(* Small helpers to avoid catching ocaml-runtime exceptions *)
714- type exception_filter = exn -> bool
715- let catch_filter__all = fun _ -> true
716- let catch_filter__all_except_runtime = function
717- | Out_of_memory -> false
718- | Stack_overflow -> false
719- | _ -> true
720- let exception_filter =
721- (* Default value: the legacy behaviour to avoid breaking programs *)
722- ref catch_filter__all
723- let set_exception_filter f = exception_filter := f
724- let filter_exception e = ! exception_filter e
714+ module Exception_filter = struct
715+ type t = exn -> bool
716+ let handle_all = fun _ -> true
717+ let handle_all_except_runtime = function
718+ | Out_of_memory -> false
719+ | Stack_overflow -> false
720+ | _ -> true
721+ let v =
722+ (* Default value: the legacy behaviour to avoid breaking programs *)
723+ ref handle_all
724+ let set f = v := f
725+ let run e = ! v e
726+ end
725727
726728module Sequence_associated_storage :
727729sig
@@ -802,7 +804,7 @@ struct
802804 let result = f () in
803805 current_storage := saved_storage;
804806 result
805- with exn when ! exception_filter exn ->
807+ with exn when Exception_filter. run exn ->
806808 current_storage := saved_storage;
807809 raise exn
808810end
@@ -1140,7 +1142,7 @@ struct
11401142 be reject later, it is not the responsibility of this function to pass
11411143 the exception to [!async_exception_hook]. *)
11421144 try f v
1143- with exn when ! exception_filter exn ->
1145+ with exn when Exception_filter. run exn ->
11441146 ! async_exception_hook exn
11451147
11461148
@@ -1840,7 +1842,7 @@ struct
18401842
18411843 let p' =
18421844 try f v with exn
1843- when ! exception_filter exn -> fail exn
1845+ when Exception_filter. run exn -> fail exn
18441846 in
18451847 let Internal p' = to_internal_promise p' in
18461848 (* Run the user's function [f]. *)
@@ -1906,7 +1908,7 @@ struct
19061908
19071909 let p' =
19081910 try f v
1909- with exn when ! exception_filter exn ->
1911+ with exn when Exception_filter. run exn ->
19101912 fail (add_loc exn ) in
19111913 let Internal p' = to_internal_promise p' in
19121914
@@ -1963,7 +1965,7 @@ struct
19631965
19641966 let p''_result =
19651967 try Fulfilled (f v) with exn
1966- when ! exception_filter exn -> Rejected exn
1968+ when Exception_filter. run exn -> Rejected exn
19671969 in
19681970
19691971 let State_may_now_be_pending_proxy p'' = may_now_be_proxy p'' in
@@ -1993,7 +1995,7 @@ struct
19931995 to_public_promise
19941996 {state =
19951997 try Fulfilled (f v)
1996- with exn when ! exception_filter exn -> Rejected exn })
1998+ with exn when Exception_filter. run exn -> Rejected exn })
19971999 ~if_deferred: (fun () ->
19982000 let (p'', callback) =
19992001 create_result_promise_and_callback_if_deferred () in
@@ -2012,7 +2014,7 @@ struct
20122014 let catch f h =
20132015 let p =
20142016 try f ()
2015- with exn when ! exception_filter exn -> fail exn
2017+ with exn when Exception_filter. run exn -> fail exn
20162018 in
20172019 let Internal p = to_internal_promise p in
20182020 let p = underlying p in
@@ -2037,7 +2039,7 @@ struct
20372039
20382040 let p' =
20392041 try h exn
2040- with exn when ! exception_filter exn -> fail exn
2042+ with exn when Exception_filter. run exn -> fail exn
20412043 in
20422044 let Internal p' = to_internal_promise p' in
20432045
@@ -2073,7 +2075,7 @@ struct
20732075 let backtrace_catch add_loc f h =
20742076 let p =
20752077 try f ()
2076- with exn when ! exception_filter exn -> fail exn
2078+ with exn when Exception_filter. run exn -> fail exn
20772079 in
20782080 let Internal p = to_internal_promise p in
20792081 let p = underlying p in
@@ -2098,7 +2100,7 @@ struct
20982100
20992101 let p' =
21002102 try h exn
2101- with exn when ! exception_filter exn ->
2103+ with exn when Exception_filter. run exn ->
21022104 fail (add_loc exn )
21032105 in
21042106 let Internal p' = to_internal_promise p' in
@@ -2135,7 +2137,7 @@ struct
21352137 let try_bind f f' h =
21362138 let p =
21372139 try f ()
2138- with exn when ! exception_filter exn -> fail exn
2140+ with exn when Exception_filter. run exn -> fail exn
21392141 in
21402142 let Internal p = to_internal_promise p in
21412143 let p = underlying p in
@@ -2152,7 +2154,7 @@ struct
21522154
21532155 let p' =
21542156 try f' v
2155- with exn when ! exception_filter exn -> fail exn
2157+ with exn when Exception_filter. run exn -> fail exn
21562158 in
21572159 let Internal p' = to_internal_promise p' in
21582160
@@ -2168,7 +2170,7 @@ struct
21682170
21692171 let p' =
21702172 try h exn
2171- with exn when ! exception_filter exn -> fail exn
2173+ with exn when Exception_filter. run exn -> fail exn
21722174 in
21732175 let Internal p' = to_internal_promise p' in
21742176
@@ -2210,7 +2212,7 @@ struct
22102212 let backtrace_try_bind add_loc f f' h =
22112213 let p =
22122214 try f ()
2213- with exn when ! exception_filter exn -> fail exn
2215+ with exn when Exception_filter. run exn -> fail exn
22142216 in
22152217 let Internal p = to_internal_promise p in
22162218 let p = underlying p in
@@ -2227,7 +2229,7 @@ struct
22272229
22282230 let p' =
22292231 try f' v
2230- with exn when ! exception_filter exn ->
2232+ with exn when Exception_filter. run exn ->
22312233 fail (add_loc exn )
22322234 in
22332235 let Internal p' = to_internal_promise p' in
@@ -2244,7 +2246,7 @@ struct
22442246
22452247 let p' =
22462248 try h exn
2247- with exn when ! exception_filter exn ->
2249+ with exn when Exception_filter. run exn ->
22482250 fail (add_loc exn )
22492251 in
22502252 let Internal p' = to_internal_promise p' in
@@ -2499,7 +2501,7 @@ struct
24992501 let dont_wait f h =
25002502 let p =
25012503 try f ()
2502- with exn when ! exception_filter exn -> fail exn
2504+ with exn when Exception_filter. run exn -> fail exn
25032505 in
25042506 let Internal p = to_internal_promise p in
25052507
@@ -2522,7 +2524,7 @@ struct
25222524 let async f =
25232525 let p =
25242526 try f ()
2525- with exn when ! exception_filter exn -> fail exn
2527+ with exn when Exception_filter. run exn -> fail exn
25262528 in
25272529 let Internal p = to_internal_promise p in
25282530
@@ -3125,39 +3127,39 @@ struct
31253127
31263128
31273129 let apply f x =
3128- try f x with exn when ! exception_filter exn -> fail exn
3130+ try f x with exn when Exception_filter. run exn -> fail exn
31293131
31303132 let wrap f =
31313133 try return (f () )
3132- with exn when ! exception_filter exn -> fail exn
3134+ with exn when Exception_filter. run exn -> fail exn
31333135
31343136 let wrap1 f x1 =
31353137 try return (f x1)
3136- with exn when ! exception_filter exn -> fail exn
3138+ with exn when Exception_filter. run exn -> fail exn
31373139
31383140 let wrap2 f x1 x2 =
31393141 try return (f x1 x2)
3140- with exn when ! exception_filter exn -> fail exn
3142+ with exn when Exception_filter. run exn -> fail exn
31413143
31423144 let wrap3 f x1 x2 x3 =
31433145 try return (f x1 x2 x3)
3144- with exn when ! exception_filter exn -> fail exn
3146+ with exn when Exception_filter. run exn -> fail exn
31453147
31463148 let wrap4 f x1 x2 x3 x4 =
31473149 try return (f x1 x2 x3 x4)
3148- with exn when ! exception_filter exn -> fail exn
3150+ with exn when Exception_filter. run exn -> fail exn
31493151
31503152 let wrap5 f x1 x2 x3 x4 x5 =
31513153 try return (f x1 x2 x3 x4 x5)
3152- with exn when ! exception_filter exn -> fail exn
3154+ with exn when Exception_filter. run exn -> fail exn
31533155
31543156 let wrap6 f x1 x2 x3 x4 x5 x6 =
31553157 try return (f x1 x2 x3 x4 x5 x6)
3156- with exn when ! exception_filter exn -> fail exn
3158+ with exn when Exception_filter. run exn -> fail exn
31573159
31583160 let wrap7 f x1 x2 x3 x4 x5 x6 x7 =
31593161 try return (f x1 x2 x3 x4 x5 x6 x7)
3160- with exn when ! exception_filter exn -> fail exn
3162+ with exn when Exception_filter. run exn -> fail exn
31613163
31623164
31633165
0 commit comments