1 (* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA *)
3 This file is part of mldonkey.
5 mldonkey is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 mldonkey is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mldonkey; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 Obj.magic
(match Sys.os_type
with
25 | "MacOS" -> "File \"%s\"; line %d; characters %d to %d ### %s"
26 | _
-> "File \"%s\", line %d, characters %d-%d: %s")
30 let f = Obj.field x i
in
31 if not
(Obj.is_block
f) then
32 sprintf
"%d" (Obj.magic
f : int) (* can also be a char *)
33 else if Obj.tag
f = Obj.string_tag
then
34 sprintf
"\"%s\"" (String.escaped
(Obj.magic
f : string))
35 else if Obj.tag
f = Obj.double_tag
then
36 string_of_float
(Obj.magic
f : float)
40 let rec other_fields x i
=
41 if i
>= Obj.size x
then ""
42 else sprintf
", %s%s" (field x i
) (other_fields x
(i
+1))
48 | 2 -> sprintf
"(%s)" (field x
1)
49 | n
-> sprintf
"(%s%s)" (field x
1) (other_fields x
2)
54 let rec check exn
printers =
57 | printer
:: printers ->
58 try printer exn
with _
->
61 let to_string = function
62 | Out_of_memory
-> "Out of memory";
63 | Stack_overflow
-> "Stack overflow";
64 | Match_failure
(file
, first_char
, last_char
) ->
65 sprintf
locfmt file
0 first_char last_char
"Pattern matching failed";
66 | Assert_failure
(file
, first_char
, last_char
) ->
67 sprintf
locfmt file
0 first_char last_char
"Assertion failed";
73 let constructor = (Obj.magic
(Obj.field (Obj.field x 0) 0) : string) in
74 constructor ^
(fields x)
81 eprintf
"Uncaught exception: %s\n" (to_string x);
85 let register_exn f = printers := f :: !printers
90 lprintf_nl
"Uncaught exception in %s: %s" s
(to_string e
)
95 lprintf_nl
"Uncaught exception in %s: %s" s
(to_string e
)
100 lprintf_nl
"Uncaught exception in %s: %s" s
(to_string e
);
104 register_exn (fun e
->
106 Unix.Unix_error
(e
, f, arg
) ->
107 Printf.sprintf
"%s failed%s: %s" f (if arg
= "" then "" else
108 " on " ^ arg
) (Unix.error_message e
)