19 |
|
|
20 |
open Printf2;; |
open Printf2;; |
21 |
open Printf |
open Printf |
22 |
|
|
23 |
let locfmt = |
let locfmt = |
24 |
Obj.magic (match Sys.os_type with |
Obj.magic (match Sys.os_type with |
25 |
| "MacOS" -> "File \"%s\"; line %d; characters %d to %d ### %s" |
| "MacOS" -> "File \"%s\"; line %d; characters %d to %d ### %s" |
83 |
raise x |
raise x |
84 |
|
|
85 |
let register_exn f = printers := f :: !printers |
let register_exn f = printers := f :: !printers |
86 |
|
|
87 |
let catch s f x = |
let catch s f x = |
88 |
try f x with |
try f x with |
89 |
e -> |
e -> |
90 |
lprintf "Uncaught exception in %s: %s" s (to_string e); |
lprintf_nl "Uncaught exception in %s: %s" s (to_string e) |
91 |
lprint_newline () |
|
|
|
|
92 |
let catch2 s f x y = |
let catch2 s f x y = |
93 |
try f x y with |
try f x y with |
94 |
e -> |
e -> |
95 |
lprintf "Uncaught exception in %s: %s" s (to_string e); |
lprintf_nl "Uncaught exception in %s: %s" s (to_string e) |
96 |
lprint_newline () |
|
|
|
|
97 |
let vcatchexn s f = |
let vcatchexn s f = |
98 |
try Some (f ()) with |
try Some (f ()) with |
99 |
e -> |
e -> |
100 |
lprintf "Uncaught exception in %s: %s" s (to_string e); |
lprintf_nl "Uncaught exception in %s: %s" s (to_string e); |
|
lprint_newline (); |
|
101 |
None |
None |
102 |
|
|
103 |
let _ = |
let _ = |
104 |
register_exn (fun e -> |
register_exn (fun e -> |
105 |
match e with |
match e with |
106 |
Unix.Unix_error (e, f, arg) -> |
Unix.Unix_error (e, f, arg) -> |
107 |
Printf.sprintf "%s failed%s: %s" f (if arg = "" then "" else |
Printf.sprintf "%s failed%s: %s" f (if arg = "" then "" else |
108 |
"on " ^ arg) (Unix.error_message e) |
"on " ^ arg) (Unix.error_message e) |
109 |
| _ -> raise e |
| _ -> raise e |
110 |
) |
) |