exportation de Printexc.print_exn et customisation Mac

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1581 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Damien Doligez 1997-06-06 14:54:09 +00:00
parent 96b8fedbf1
commit 28a67e328e
2 changed files with 15 additions and 10 deletions

View File

@ -11,22 +11,24 @@
(* $Id$ *)
let prerr_loc file first_char last_char msg =
prerr_string "File \"";
prerr_string file;
prerr_string "\", line 0, characters "; prerr_int first_char;
prerr_char '-'; prerr_int last_char; prerr_string ": ";
prerr_string msg; prerr_char '\n'
open Printf;;
let locfmt =
match Sys.os_type with
| "MacOS" -> ("File \"%s\"; line %d; characters %d to %d ### %s\n"
: ('a, 'b, 'c) format)
| _ -> ("File \"%s\", line %d, characters %d-%d: %s\n" : ('a, 'b, 'c) format)
;;
let print_exn = function
Out_of_memory ->
prerr_string "Out of memory\n"
prerr_string "Out of memory\n";
| Stack_overflow ->
prerr_string "Stack overflow\n"
prerr_string "Stack overflow\n";
| Match_failure(file, first_char, last_char) ->
prerr_loc file first_char last_char "Pattern matching failed";
eprintf locfmt file first_char last_char "Pattern matching failed";
| Assert_failure(file, first_char, last_char) ->
prerr_loc file first_char last_char "Assertion failed";
eprintf locfmt file first_char last_char "Assertion failed";
| x ->
prerr_string "Uncaught exception: ";
prerr_string (Obj.magic(Obj.field (Obj.field (Obj.repr x) 0) 0));

View File

@ -25,3 +25,6 @@ val catch: ('a -> 'b) -> 'a -> 'b
val print: ('a -> 'b) -> 'a -> 'b
(* Same as [catch], but re-raise the stray exception after
printing it, instead of aborting the program. *)
val print_exn: exn -> unit
(* [print_exn e] prints [e] on standard error output. *)