Files
langkit/testsuite/c_support/utils_exec.c
Pierre-Marie de Rodat e3d641f973 C API: symbolize exception stack traces only on demand
Symbolization is a costly operation: do it only when requested. Rework
the C API to make this possible. For now, do it automatically in the
Java API to avoid breaking existing Java programs: this will fix the
performance situation in the other C-based APIs.
2025-03-10 13:49:16 +00:00

37 lines
828 B
C

#include <stdio.h>
#include <stdlib.h>
#include <libfoolang.h>
#include "utils_exc.h"
/* Print the exception that was raised by the last API call. When
there was no such exception, print nothing if OR_SILENT, and print "Got no
exception" otherwise. Return if there was an exception. */
bool
print_exception (bool or_silent)
{
const foo_exception *exc = foo_get_last_exception ();
if (exc != NULL)
{
char *exc_name = foo_exception_name (exc->kind);
printf ("Got an exception (%s):\n %s\n",
exc_name,
exc->information);
free (exc_name);
}
else if (! or_silent)
puts ("Got no exception\n");
return false;
}
/* If the last API call raised an error, print it and abort the process. */
void
abort_on_exception (void)
{
if (print_exception (true))
exit (1);
}