Example #1
0
/* Default C implementation in case the OCaml one is not registered. */
static void default_fatal_uncaught_exception(value exn)
{
  char * msg;
  caml_root at_exit;
  int saved_backtrace_active;
  intnat saved_backtrace_pos;
  caml_domain_state* domain_state = Caml_state;

  /* Build a string representation of the exception */
  msg = caml_format_exception(exn);
  /* Perform "at_exit" processing, ignoring all exceptions that may
     be triggered by this */
  saved_backtrace_active = domain_state->backtrace_active;
  saved_backtrace_pos = domain_state->backtrace_pos;
  domain_state->backtrace_active = 0;
  at_exit = caml_named_root("Pervasives.do_at_exit");
  if (at_exit) caml_callback_exn(caml_read_root(at_exit), Val_unit);
  domain_state->backtrace_active = saved_backtrace_active;
  domain_state->backtrace_pos = saved_backtrace_pos;
  /* Display the uncaught exception */
  fprintf(stderr, "Fatal error: exception %s\n", msg);
  free(msg);
  /* Display the backtrace if available */
  if (Caml_state->backtrace_active && !DEBUGGER_IN_USE)
    caml_print_exception_backtrace();
}
void caml_fatal_uncaught_exception(value exn)
{
  char * msg;
  value * at_exit;
  int saved_backtrace_active, saved_backtrace_pos;

  /* Build a string representation of the exception */
  msg = caml_format_exception(exn);
  /* Perform "at_exit" processing, ignoring all exceptions that may
     be triggered by this */
  saved_backtrace_active = caml_backtrace_active;
  saved_backtrace_pos = caml_backtrace_pos;
  caml_backtrace_active = 0;
  at_exit = caml_named_value("Pervasives.do_at_exit");
  if (at_exit != NULL) caml_callback_exn(*at_exit, Val_unit);
  caml_backtrace_active = saved_backtrace_active;
  caml_backtrace_pos = saved_backtrace_pos;
  /* Display the uncaught exception */
  fprintf(stderr, "Fatal error: exception %s\n", msg);
  free(msg);
  /* Display the backtrace if available */
  if (caml_backtrace_active
#ifndef NATIVE_CODE
      && !caml_debugger_in_use
#endif
      ) {
    caml_print_exception_backtrace();
  }
  /* Terminate the process */
  exit(2);
}