Permalink
Browse files

[GH #816] Check if you're dying by interp->final_exception

In a branch of mod_parrot designed to ease the writing of
exception handlers, I noted that the API cannot catch exceptions twice.
On throwing an exception and the interpreter 'dies', it returns to the
api call via longjmp(), and sets some values upon the interpreter object.
Based upon these values, the api call returns 0, upon which the exception
is retrieved and inspected. Best example: show_last_error_and_exit.

We should just check for the last_exception being PMCNULL; if so you can
jump out (we are already dying) and if not set already_dying.
  • Loading branch information...
1 parent da9adfa commit 29545e98247995b86c4d65c816da011950258e14 @bdw bdw committed with Reini Urban Aug 21, 2012
Showing with 3 additions and 4 deletions.
  1. +3 −4 src/exceptions.c
View
@@ -108,21 +108,20 @@ die_from_exception(PARROT_INTERP, ARGIN(PMC *exception))
ASSERT_ARGS(die_from_exception)
/* Avoid anything that can throw if we are already throwing from
* a previous call to this function */
- static int already_dying = 0;
-
+ int already_dying = !PMC_IS_NULL(interp->final_exception);
STRING * const message = already_dying ? STRINGNULL :
VTABLE_get_string(interp, exception);
const INTVAL severity = already_dying ? (INTVAL)EXCEPT_fatal :
VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "severity"));
- if (already_dying)
+ if (already_dying) {
Parrot_x_jump_out(interp, 1);
+ }
else {
/* In some cases we have a fatal exception before the IO system
* is completely initialized. Do some attempt to output the
* message to stderr, to help diagnosing. */
const int use_perr = !PMC_IS_NULL(Parrot_io_STDERR(interp));
- already_dying = 1;
interp->final_exception = exception;
interp->exit_code = 1;

0 comments on commit 29545e9

Please sign in to comment.