MDL-20636 Reveiw all throw statements.

This commit is contained in:
Tim Hunt 2011-02-23 16:50:09 +00:00
parent f7970e3ca7
commit 88f0eb1546
15 changed files with 56 additions and 80 deletions

View file

@ -70,7 +70,7 @@ abstract class question_bank {
$file = get_plugin_directory('qtype', $qtypename) . '/questiontype.php';
if (!is_readable($file)) {
if ($mustexist || $qtypename == 'missingtype') {
throw new Exception('Unknown question type ' . $qtypename);
throw new coding_exception('Unknown question type ' . $qtypename);
} else {
return self::get_qtype('missingtype');
}
@ -186,7 +186,7 @@ abstract class question_bank {
}
$file = $CFG->dirroot . '/question/type/' . $qtypename . '/question.php';
if (!is_readable($file)) {
throw new Exception('Unknown question type (no definition) ' . $qtypename);
throw new coding_exception('Unknown question type (no definition) ' . $qtypename);
}
include_once($file);
self::$loadedqdefs[$qtypename] = 1;
@ -256,7 +256,7 @@ abstract class question_bank {
private static function return_test_question_data($questionid) {
if (!isset(self::$testdata[$questionid])) {
throw new Exception('question_bank::return_test_data(' . $questionid .
throw new coding_exception('question_bank::return_test_data(' . $questionid .
') called, but no matching question has been loaded by load_test_data.');
}
return self::$testdata[$questionid];
@ -269,7 +269,7 @@ abstract class question_bank {
*/
public static function load_test_question_data(question_definition $question) {
if (!self::$testmode) {
throw new Exception('question_bank::load_test_data called when not in test mode.');
throw new coding_exception('question_bank::load_test_data called when not in test mode.');
}
self::$testdata[$question->id] = $question;
}

View file

@ -150,7 +150,7 @@ WHERE
", array('stepid' => $stepid));
if (!$records) {
throw new Exception('Failed to load question_attempt_step ' . $stepid);
throw new coding_exception('Failed to load question_attempt_step ' . $stepid);
}
return question_attempt_step::load_from_records($records, $stepid);
@ -202,7 +202,7 @@ ORDER BY
", array('questionattemptid' => $questionattemptid));
if (!$records) {
throw new Exception('Failed to load question_attempt ' . $questionattemptid);
throw new coding_exception('Failed to load question_attempt ' . $questionattemptid);
}
$record = current($records);
@ -259,7 +259,7 @@ ORDER BY
", array('qubaid' => $qubaid));
if (!$records) {
throw new Exception('Failed to load questions_usage_by_activity ' . $qubaid);
throw new coding_exception('Failed to load questions_usage_by_activity ' . $qubaid);
}
return question_usage_by_activity::load_from_records($records, $qubaid);
@ -599,9 +599,7 @@ ORDER BY
$record->component = addslashes($quba->get_owning_component());
$record->preferredbehaviour = addslashes($quba->get_preferred_behaviour());
if (!$this->db->update_record('question_usages', $record)) {
throw new Exception('Failed to update question_usage_by_activity ' . $record->id);
}
$this->db->update_record('question_usages', $record);
}
/**
@ -620,9 +618,7 @@ ORDER BY
$record->responsesummary = addslashes($qa->get_response_summary());
$record->timemodified = time();
if (!$this->db->update_record('question_attempts', $record)) {
throw new Exception('Failed to update question_attempt ' . $record->id);
}
$this->db->update_record('question_attempts', $record);
}
/**
@ -696,7 +692,7 @@ ORDER BY
public function update_question_attempt_flag($qubaid, $questionid, $qaid, $slot, $newstate) {
if (!$this->db->record_exists('question_attempts', array('id' => $qaid,
'questionusageid' => $qubaid, 'questionid' => $questionid, 'slot' => $slot))) {
throw new Exception('invalid ids');
throw new moodle_exception('errorsavingflags', 'question');
}
$this->db->set_field('question_attempts', 'flagged', $newstate, array('id' => $qaid));
@ -1002,7 +998,7 @@ class qubaid_list extends qubaid_condition {
global $DB;
if (is_null($this->columntotest)) {
throw new coding_exception('Must call another method that before where().');
throw new coding_exception('Must call from_question_attempts before where().');
}
if (empty($this->qubaids)) {
$this->params = array();

View file

@ -144,7 +144,7 @@ abstract class question_engine {
question_engine::load_behaviour_class($preferredbehaviour);
$class = 'qbehaviour_' . $preferredbehaviour;
if (!constant($class . '::IS_ARCHETYPAL')) {
throw new Exception('The requested behaviour is not actually an archetypal one.');
throw new coding_exception('The requested behaviour is not actually an archetypal one.');
}
return new $class($qa, $preferredbehaviour);
}
@ -200,7 +200,7 @@ abstract class question_engine {
}
$file = $CFG->dirroot . '/question/behaviour/' . $behaviour . '/behaviour.php';
if (!is_readable($file)) {
throw new Exception('Unknown question behaviour ' . $behaviour);
throw new coding_exception('Unknown question behaviour ' . $behaviour);
}
include_once($file);
self::$loadedbehaviours[$behaviour] = 1;
@ -545,7 +545,7 @@ abstract class question_flags {
// probably makes it sufficiently difficult for malicious users to toggle
// other users flags.
if ($checksum != question_flags::get_toggle_checksum($qubaid, $questionid, $qaid, $slot)) {
throw new Exception('checksum failure');
throw new moodle_exception('errorsavingflags', 'question');
}
$dm = new question_engine_data_mapper();
@ -785,7 +785,7 @@ class question_usage_by_activity {
*/
protected function check_slot($slot) {
if (!array_key_exists($slot, $this->questionattempts)) {
throw new exception("There is no question_attempt number $slot in this attempt.");
throw new coding_exception("There is no question_attempt number $slot in this attempt.");
}
}
@ -1198,7 +1198,7 @@ class question_usage_by_activity {
while ($record->qubaid != $qubaid) {
$record = next($records);
if (!$record) {
throw new Exception("Question usage $qubaid not found in the database.");
throw new coding_exception("Question usage $qubaid not found in the database.");
}
}
@ -1280,10 +1280,10 @@ class question_attempt_iterator implements Iterator, ArrayAccess {
return $this->quba->get_question_attempt($slot);
}
public function offsetSet($slot, $value) {
throw new Exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot set.');
throw new coding_exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot set.');
}
public function offsetUnset($slot) {
throw new Exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot unset.');
throw new coding_exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot unset.');
}
}
@ -1561,7 +1561,7 @@ class question_attempt {
*/
public function get_step($i) {
if ($i < 0 || $i >= count($this->steps)) {
throw new Exception('Index out of bounds in question_attempt::get_step.');
throw new coding_exception('Index out of bounds in question_attempt::get_step.');
}
return $this->steps[$i];
}
@ -1755,7 +1755,7 @@ class question_attempt {
/** @return number the maximum mark possible for this question attempt. */
public function get_min_fraction() {
if (is_null($this->minfraction)) {
throw new Exception('This question_attempt has not been started yet, the min fraction is not yet konwn.');
throw new coding_exception('This question_attempt has not been started yet, the min fraction is not yet konwn.');
}
return $this->minfraction;
}
@ -2207,7 +2207,7 @@ class question_attempt {
while ($record->questionattemptid != $questionattemptid) {
$record = next($records);
if (!$record) {
throw new Exception("Question attempt $questionattemptid not found in the database.");
throw new coding_exception("Question attempt $questionattemptid not found in the database.");
}
}
@ -2384,10 +2384,10 @@ class question_attempt_step_iterator implements Iterator, ArrayAccess {
return $this->qa->get_step($i);
}
public function offsetSet($offset, $value) {
throw new Exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot set.');
throw new coding_exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot set.');
}
public function offsetUnset($offset) {
throw new Exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot unset.');
throw new coding_exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot unset.');
}
}
@ -2554,7 +2554,7 @@ class question_attempt_step {
*/
public function set_qt_var($name, $value) {
if ($name[0] != '_') {
throw new Exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.');
throw new coding_exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.');
}
$this->data[$name] = $value;
}
@ -2599,7 +2599,7 @@ class question_attempt_step {
*/
public function set_behaviour_var($name, $value) {
if ($name[0] != '_') {
throw new Exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.');
throw new coding_exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.');
}
return $this->data['-' . $name] = $value;
}
@ -2659,7 +2659,7 @@ class question_attempt_step {
while ($currentrec->attemptstepid != $attemptstepid) {
$currentrec = next($records);
if (!$currentrec) {
throw new Exception("Question attempt step $attemptstepid not found in the database.");
throw new coding_exception("Question attempt step $attemptstepid not found in the database.");
}
}
@ -2750,7 +2750,7 @@ class question_null_step {
}
public function set_state($state) {
throw new Exception('This question has not been started.');
throw new coding_exception('This question has not been started.');
}
public function get_fraction() {

View file

@ -314,7 +314,7 @@ abstract class testing_db_record_builder {
$records = array();
foreach ($table as $row) {
if (count($row) != count($columns)) {
throw new Exception("Row contains the wrong number of fields.");
throw new coding_exception("Row contains the wrong number of fields.");
}
$rec = new stdClass();
foreach ($columns as $i => $name) {

View file

@ -98,7 +98,7 @@ abstract class question_state {
}
}
if (empty($states)) {
throw new Exception('unknown summary state ' . $summarystate);
throw new coding_exception('unknown summary state ' . $summarystate);
}
return $states;
}
@ -246,7 +246,7 @@ abstract class question_state {
* @return int the new state.
*/
public function corresponding_commented_state($fraction) {
throw new Exception('Unexpected question state.');
throw new coding_exception('Unexpected question state.');
}
/**
@ -295,7 +295,7 @@ class question_state_notstarted extends question_state {
return false;
}
public function get_state_class($showcorrectness) {
throw new Exception('Unexpected question state.');
throw new coding_exception('Unexpected question state.');
}
}
class question_state_unprocessed extends question_state {
@ -303,7 +303,7 @@ class question_state_unprocessed extends question_state {
return false;
}
public function get_state_class($showcorrectness) {
throw new Exception('Unexpected question state.');
throw new coding_exception('Unexpected question state.');
}
}
class question_state_todo extends question_state {