Exemple #1
0
static void
show_last_error_and_exit(Parrot_PMC interp)
{
    Parrot_Int    is_error,
                  exit_code;
    Parrot_String errmsg,
                  backtrace;
    Parrot_PMC    exception;

    /* Get result of last API function call and exception backtrace */
    if (!(Parrot_api_get_result(interp, &is_error, &exception, &exit_code, &errmsg)
        && Parrot_api_get_exception_backtrace(interp, exception, &backtrace))) {

        fprintf(stderr, "PARROT VM: Cannot recover\n");
        exit(EXIT_FAILURE);
    }

    /* Check for unhandled exceptions */
    if (is_error) {
        char *msg;

        /* Display error message */
        Parrot_api_string_export_ascii(interp, errmsg, &msg);
        fprintf(stderr, "%s\n", msg);
        Parrot_api_string_free_exported_ascii(interp, msg);

        /* Display exception backtrace */
        Parrot_api_string_export_ascii(interp, backtrace, &msg);
        fprintf(stderr, "%s\n", msg);
        Parrot_api_string_free_exported_ascii(interp, msg);
    }

    exit(exit_code);
}
Exemple #2
0
static void
show_last_error_and_exit(Parrot_PMC interp)
{
    Parrot_String errmsg, backtrace;
    Parrot_Int exit_code, is_error;
    Parrot_PMC exception;

    if (!(Parrot_api_get_result(interp, &is_error, &exception, &exit_code, &errmsg) &&
            Parrot_api_get_exception_backtrace(interp, exception, &backtrace))) {
        fprintf(stderr, "PARROT VM: Cannot recover\n");
        exit(EXIT_FAILURE);
    }

    if (errmsg) {
        char * errmsg_raw;
        Parrot_api_string_export_ascii(interp, errmsg, &errmsg_raw);
        fprintf(stderr, "%s\n", errmsg_raw);
        Parrot_api_string_free_exported_ascii(interp, errmsg_raw);

        Parrot_api_string_export_ascii(interp, backtrace, &errmsg_raw);
        fprintf(stderr, "%s\n", errmsg_raw);
        Parrot_api_string_free_exported_ascii(interp, errmsg_raw);
    }
    exit(exit_code);
}
Exemple #3
0
        static void
        print_parrot_string(Parrot_PMC interp, FILE *vector, Parrot_String str, int newline)
        {
            char *msg_raw;

            if (!str)
                return;

            if (!Parrot_api_string_export_ascii(interp, str, &msg_raw))
                show_last_error_and_exit(interp);

            if (msg_raw) {
                fprintf(vector, "%s%s", msg_raw, newline ? "\n" : "");

                if (!Parrot_api_string_free_exported_ascii(interp, msg_raw))
                    show_last_error_and_exit(interp);
            }
        }