Index: src/pmc/exceptionhandler.pmc =================================================================== --- src/pmc/exceptionhandler.pmc (revision 42318) +++ src/pmc/exceptionhandler.pmc (working copy) @@ -22,12 +22,16 @@ #include "parrot/oplib/ops.h" +/* Arbitrarily choosen value */ +#define HANDLING_COUNTER_LIMIT 512 + pmclass ExceptionHandler extends Continuation auto_attrs { ATTR PMC *handled_types; ATTR PMC *handled_types_except; ATTR INTVAL min_severity; ATTR INTVAL max_severity; + ATTR INTVAL handling_counter; /* @@ -120,6 +124,10 @@ VTABLE opcode_t *invoke(void *next) { opcode_t * const pc = PARROT_CONTINUATION(SELF)->address; + INTVAL counter; + GET_ATTR_handling_counter(INTERP, SELF, counter); + ++counter; + SET_ATTR_handling_counter(INTERP, SELF, counter); Parrot_continuation_check(interp, SELF); Parrot_continuation_rewind_environment(interp, SELF); @@ -158,8 +166,18 @@ STRING * const sev = CONST_STRING(interp, "severity"); STRING * const ex_str = CONST_STRING(interp, "Exception"); - INTVAL severity = VTABLE_get_integer_keyed_str(interp, exception, sev); + const INTVAL severity = VTABLE_get_integer_keyed_str(interp, exception, sev); + const INTVAL type = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "type")); + /* Declare that it can't handle any exception after reaching the limit, + * giving opportunity to other handler to take control. + * Avoid control exceptions, that are supposed to be less error prone + * and might need longer usages. */ + INTVAL counter; + GET_ATTR_handling_counter(INTERP, SELF, counter); + if (type < CONTROL_RETURN && counter >= HANDLING_COUNTER_LIMIT) + RETURN(INTVAL 0); + if (exception->vtable->base_type == enum_class_Exception || VTABLE_isa(INTERP, exception, ex_str)) { PMC *handled_types; @@ -178,7 +196,6 @@ } if (! PMC_IS_NULL(handled_types)) { const INTVAL elems = VTABLE_elements(interp, handled_types); - const INTVAL type = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "type")); INTVAL i; for (i = 0; i < elems; i++) {