void ribi::qthideandshowdialog_test::destroy_cleanly_upon_exception_in_derived_class()
{
  if ("this will freeze") return;
  QtHideAndShowDialog parent;
  QtHideAndShowAndThrowDialog kid;
  parent.show();
  QVERIFY(parent.isVisible());
  QVERIFY(!kid.isVisible());

  //Make the kid throw an exception after one second
  std::unique_ptr<QTimer> timer(new QTimer);
  timer->setInterval(1000);
  QObject::connect(timer.get(), SIGNAL(timeout()), &kid, SLOT(do_throw()));
  timer->start();

  try
  {
    parent.ShowChild(&kid);
    QVERIFY(!"Should not get here");
  }
  catch (std::exception& )
  {
    //OK
    QVERIFY("Should get here");
  }
}
Пример #2
0
G_GNUC_NORETURN WS_MSVC_NORETURN void except_rethrow(except_t *except)
{
    struct except_stacknode *top = get_top();
    assert (top != 0);
    assert (top->except_type == XCEPT_CATCHER);
    assert (&top->except_info.except_catcher->except_obj == except);
    set_top(top->except_down);
    do_throw(except);
}
Пример #3
0
void except_rethrow(except_t *except)
{
    struct except_stacknode *top = get_top();
    assert (top != 0);
    assert (top->type == XCEPT_CATCHER);
    assert (&top->info.catcher->obj == except);
    set_top(top->down);
    do_throw(except);
}
Пример #4
0
G_GNUC_NORETURN WS_MSVC_NORETURN void except_throwd(long group, long code, const char *msg, void *data)
{
    except_t except;

    except.except_id.except_group = group;
    except.except_id.except_code = code;
    except.except_message = msg;
    except.except_dyndata = data;

    do_throw(&except);
}
Пример #5
0
void except_throwd(long group, long code, const char *msg, void *data)
{
    except_t except;

    except.id.group = group;
    except.id.code = code;
    except.message = msg;
    except.dyndata = data;

    do_throw(&except);
}
Пример #6
0
G_GNUC_NORETURN WS_MSVC_NORETURN void except_throw(long group, long code, const char *msg)
{
    except_t except;

    except.except_id.except_group = group;
    except.except_id.except_code = code;
    except.except_message = msg;
    except.except_dyndata = 0;

#ifdef _WIN32
    if (code == DissectorError && IsDebuggerPresent()) {
        DebugBreak();
    }
#endif

    do_throw(&except);
}
Пример #7
0
/**
 * Throw an exception.
 *
 * You can also use this in a program using libparted.
 * "message" is a printf-like format string, so you can do
 *
 * \code
 * ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_RETRY_CANCEL,
 *      "Can't open %s", file_name);
 * \endcode
 *
 * Returns the option selected to resolve the exception. If the exception was
 * unhandled, PED_EXCEPTION_UNHANDLED is returned.
 */
PedExceptionOption
ped_exception_throw (PedExceptionType ex_type,
		     PedExceptionOption ex_opts, const char* message, ...)
{
	va_list		arg_list;
	int result;
	static int size = 1000;

	if (ex)
		ped_exception_catch ();

	ex = (PedException*) malloc (sizeof (PedException));
	if (!ex)
		goto no_memory;

	ex->type = ex_type;
	ex->options = ex_opts;

	while (message) {
			ex->message = (char*) malloc (size * sizeof (char));
			if (!ex->message)
					goto no_memory;

			va_start (arg_list, message);
			result = vsnprintf (ex->message, size, message, arg_list);
			va_end (arg_list);

			if (result > -1 && result < size)
					break;

			size += 10;
			free (ex->message);
	}

	return do_throw ();

no_memory:
	fputs ("Out of memory in exception handler!\n", stderr);

	va_start (arg_list, message);
	vfprintf (stderr, message, arg_list);
	va_end (arg_list);

	return PED_EXCEPTION_UNHANDLED;
}
Пример #8
0
void test( int which ) {
    try {
	// exception prone code here, that may do a throw
	do_throw( which );
    } catch (...) {
	// common error code here
	++common;
	try {
	    throw;  // re-throw to more specific handler
	} catch (ExceptA&) {
	    // handle ExceptA here
	    ++do_A;
	} catch (ExceptB&) {
	    // handle ExceptB here
	    ++do_B;
	} catch (...) {
	    // handle unknown exceptions here
	    ++do_UNK;
	}
	throw;
    }
}
Пример #9
0
/**
 * Rethrow an unhandled exception.
 * This means repeating the last ped_exception_throw() statement.
 */
PedExceptionOption
ped_exception_rethrow ()
{
	return do_throw ();
}
Пример #10
0
/**
 * Fire command for spells, range, throwing, etc.
 * @param op Object firing this.
 * @param dir Direction to fire to. */
void fire(object *op, int dir)
{
	object *weap = NULL;
	int spellcost = 0;

	/* A check for players, make sure things are groovy. This routine
	 * will change the skill of the player as appropriate in order to
	 * fire whatever is requested. In the case of spells (range_magic)
	 * it handles whether cleric or mage spell is requested to be
	 * cast. */
	if (op->type == PLAYER)
	{
		if (CONTR(op)->firemode_type == FIRE_MODE_NONE)
		{
			return;
		}

		if (CONTR(op)->firemode_type == FIRE_MODE_BOW)
		{
			CONTR(op)->shoottype = range_bow;
		}
		else if (CONTR(op)->firemode_type == FIRE_MODE_THROW)
		{
			object *tmp;

			/* Insert here test for more throwing skills */
			if (!change_skill(op, SK_THROWING))
			{
				return;
			}

			/* Special case - we must redirect the fire cmd to throwing something */
			tmp = find_throw_tag(op, (tag_t) CONTR(op)->firemode_tag1);

			if (tmp)
			{
				if (!check_skill_action_time(op, op->chosen_skill))
				{
					return;
				}

				do_throw(op, tmp, dir);
				get_skill_time(op, op->chosen_skill->stats.sp);
				CONTR(op)->action_timer = (float) (CONTR(op)->action_range - global_round_tag) / (1000000 / MAX_TIME) * 1000.0f;

				if (CONTR(op)->last_action_timer > 0)
				{
					CONTR(op)->action_timer *= -1;
				}
			}

			return;
		}
		else if (CONTR(op)->firemode_type == FIRE_MODE_SPELL)
		{
			CONTR(op)->shoottype = range_magic;
		}
		else if (CONTR(op)->firemode_type == FIRE_MODE_WAND)
		{
			/* We do a jump in fire wand if we haven one */
			CONTR(op)->shoottype = range_wand;
		}
		else if (CONTR(op)->firemode_type == FIRE_MODE_SKILL)
		{
			command_rskill(op, CONTR(op)->firemode_name);
			CONTR(op)->shoottype = range_skill;
		}
		else if (CONTR(op)->firemode_type == FIRE_MODE_SUMMON)
		{
			CONTR(op)->shoottype = range_scroll;
		}
		else
		{
			CONTR(op)->shoottype = range_none;
		}

		if (!check_skill_to_fire(op))
		{
			return;
		}
	}

	switch (CONTR(op)->shoottype)
	{
		case range_none:
			return;

		case range_bow:
			if (CONTR(op)->firemode_tag2 != -1)
			{
				/* Still need to recover from range action? */
				if (!check_skill_action_time(op, op->chosen_skill))
				{
					return;
				}

				fire_bow(op, dir);
				get_skill_time(op, op->chosen_skill->stats.sp);
				CONTR(op)->action_timer = (float) (CONTR(op)->action_range - global_round_tag) / (1000000 / MAX_TIME) * 1000.0f;

				if (CONTR(op)->last_action_timer > 0)
				{
					CONTR(op)->action_timer *= -1;
				}
			}

			return;

		/* Casting spells */
		case range_magic:
			if (!check_skill_action_time(op, op->chosen_skill))
			{
				return;
			}

			spellcost = cast_spell(op, op, dir, CONTR(op)->chosen_spell, 0, spellNormal, NULL);

			if (spells[CONTR(op)->chosen_spell].type == SPELL_TYPE_PRIEST)
			{
				op->stats.grace -= spellcost;
			}
			else
			{
				op->stats.sp -= spellcost;
			}

			/* Only change the action timer if the spell required mana/grace cost (ie, was successful). */
			if (spellcost)
			{
				CONTR(op)->action_casting = ROUND_TAG + spells[CONTR(op)->chosen_spell].time;
				CONTR(op)->action_timer = (float) (CONTR(op)->action_casting - global_round_tag) / (1000000 / MAX_TIME) * 1000.0f;

				if (CONTR(op)->last_action_timer > 0)
				{
					CONTR(op)->action_timer *= -1;
				}
			}

			return;

		case range_wand:
			for (weap = op->inv; weap != NULL; weap = weap->below)
			{
				if (weap->type == WAND && QUERY_FLAG(weap, FLAG_APPLIED))
				{
					break;
				}
			}

			if (weap == NULL)
			{
				CONTR(op)->shoottype = range_rod;
				goto trick_jump;
			}

			if (!check_skill_action_time(op, op->chosen_skill))
			{
				return;
			}

			if (weap->stats.food <= 0)
			{
				play_sound_player_only(CONTR(op), SOUND_WAND_POOF, SOUND_NORMAL, 0, 0);
				new_draw_info(NDI_UNIQUE, op, "The wand says poof.");
				return;
			}

			new_draw_info(NDI_UNIQUE, op, "fire wand");

			if (cast_spell(op, weap, dir, weap->stats.sp, 0, spellWand, NULL))
			{
				/* You now know something about it */
				SET_FLAG(op, FLAG_BEEN_APPLIED);

				if (!(--weap->stats.food))
				{
					object *tmp;

					if (weap->arch)
					{
						CLEAR_FLAG(weap, FLAG_ANIMATE);
						weap->face = weap->arch->clone.face;
						weap->speed = 0;
						update_ob_speed(weap);
					}

					if ((tmp = is_player_inv(weap)))
					{
						esrv_update_item(UPD_ANIM, tmp, weap);
					}
				}
			}

			get_skill_time(op, op->chosen_skill->stats.sp);
			CONTR(op)->action_timer = (float) (CONTR(op)->action_range - global_round_tag) / (1000000 / MAX_TIME) * 1000.0f;

			if (CONTR(op)->last_action_timer > 0)
			{
				CONTR(op)->action_timer *= -1;
			}

			return;

		case range_rod:
		case range_horn:
trick_jump:
			for (weap = op->inv; weap != NULL; weap = weap->below)
			{
				if (QUERY_FLAG(weap, FLAG_APPLIED) && weap->type == (CONTR(op)->shoottype == range_rod ? ROD : HORN))
				{
					break;
				}
			}

			if (weap == NULL)
			{
				if (CONTR(op)->shoottype == range_rod)
				{
					CONTR(op)->shoottype = range_horn;
					goto trick_jump;
				}
				else
				{
					new_draw_info_format(NDI_UNIQUE, op, "You have no tool readied.");
					return;
				}
			}

			if (!check_skill_action_time(op, op->chosen_skill))
			{
				return;
			}

			/* If the device level is higher than player's skill + 5 */
			if (weap->level > op->chosen_skill->level + 5)
			{
				int level_difference = weap->level - (op->chosen_skill->level + 5);

				/* If the level difference isn't so high, give it a small chance to succeed */
				if (level_difference > 0 && (level_difference > 10 || RANDOM() % weap->level != RANDOM() % (op->chosen_skill->level + 5)))
				{
					new_draw_info_format(NDI_UNIQUE, op, "The %s is impossible to handle for you!", weap->name);
					return;
				}
			}

			if (weap->stats.hp < spells[weap->stats.sp].sp)
			{
				play_sound_player_only(CONTR(op), SOUND_WAND_POOF, SOUND_NORMAL, 0, 0);

				if (CONTR(op)->shoottype == range_rod)
				{
					new_draw_info(NDI_UNIQUE, op, "The rod whines for a while, but nothing happens.");
				}
				else
				{
					new_draw_info(NDI_UNIQUE, op, "No matter how hard you try you can't get another note out.");
				}

				return;
			}

			if (cast_spell(op, weap, dir, weap->stats.sp, 0, CONTR(op)->shoottype == range_rod ? spellRod : spellHorn, NULL))
			{
				/* You now know something about it */
				SET_FLAG(op, FLAG_BEEN_APPLIED);
				drain_rod_charge(weap);
			}

			get_skill_time(op, op->chosen_skill->stats.sp);
			CONTR(op)->action_timer = (float) (CONTR(op)->action_range - global_round_tag) / (1000000 / MAX_TIME) * 1000.0f;

			if (CONTR(op)->last_action_timer > 0)
			{
				CONTR(op)->action_timer *= -1;
			}

			return;

		/* Control summoned monsters from scrolls */
		case range_scroll:
			CONTR(op)->shoottype = range_none;
			CONTR(op)->chosen_spell = -1;
			return;

		case range_skill:
			if (!op->chosen_skill)
			{
				if (op->type == PLAYER)
					new_draw_info(NDI_UNIQUE, op, "You have no applicable skill to use.");
				return;
			}

			if (op->chosen_skill->sub_type != ST1_SKILL_USE)
			{
				new_draw_info(NDI_UNIQUE, op, "You can't use this skill in this way.");
			}
			else
			{
				do_skill(op, dir);
			}

			return;

		default:
			new_draw_info(NDI_UNIQUE, op, "Illegal shoot type.");
			return;
	}
}