summaryrefslogtreecommitdiffstats
path: root/byterun/printexc.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>1999-02-18 16:26:16 +0000
committerXavier Leroy <xavier.leroy@inria.fr>1999-02-18 16:26:16 +0000
commitf5d4b4954b59f9a5bf40e9e23fced9029e5d2dad (patch)
tree5f552e055e56a96e8295762a5f2cf59c97de097e /byterun/printexc.c
parente5567afe2eef93f6d80fad09b8d8e2acb71eae37 (diff)
Ajout de format_caml_exception
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2294 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/printexc.c')
-rw-r--r--byterun/printexc.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/byterun/printexc.c b/byterun/printexc.c
index 19c4e6bbf..128f4d296 100644
--- a/byterun/printexc.c
+++ b/byterun/printexc.c
@@ -42,18 +42,13 @@ static void add_string(struct stringbuf *buf, char *s)
buf->ptr += len;
}
-#ifdef HAS_UI
-#define errprintf(fmt,arg) ui_print_stderr(fmt, arg)
-#else
-#define errprintf(fmt,arg) fprintf(stderr, fmt, arg)
-#endif
-
-void fatal_uncaught_exception(value exn)
+char * format_caml_exception(value exn)
{
mlsize_t start, i;
value bucket, v;
struct stringbuf buf;
char intbuf[64];
+ char * res;
buf.ptr = buf.data;
buf.end = buf.data + sizeof(buf.data) - 1;
@@ -87,7 +82,23 @@ void fatal_uncaught_exception(value exn)
add_char(&buf, ')');
}
*buf.ptr = 0; /* Terminate string */
- errprintf("Fatal error: uncaught exception %s\n", buf.data);
+ i = buf.ptr - buf.data + 1;
+ res = malloc(i);
+ if (res == NULL) return NULL;
+ bcopy(buf.data, res, i);
+ return res;
+}
+
+
+void fatal_uncaught_exception(value exn)
+{
+ char * msg = format_caml_exception(exn);
+#ifdef HAS_UI
+ ui_print_stderr("Fatal error: uncaught exception %s\n", msg);
+#else
+ fprintf(stderr, "Fatal error: uncaught exception %s\n", msg);
+#endif
+ free(msg);
#ifdef HAS_UI
ui_exit(2);
#else