]> git.mjollnir.org Git - moodle.git/commitdiff
exceptions: MDL-16175 new invalid_state_exception
authortjhunt <tjhunt>
Fri, 8 May 2009 07:47:02 +0000 (07:47 +0000)
committertjhunt <tjhunt>
Fri, 8 May 2009 07:47:02 +0000 (07:47 +0000)
This is for those situations where something basically impossible happens,
like $context->contextlevel not having one of the valid value, and you
want to throw an exception (for example in the default: case of a switch)
rather than just ignoring the possibility.

lang/en_utf8/error.php
lib/setuplib.php

index cc63f07081f34044d5cc864bde0e15be548f852e..96f687c046b54fc3e1533acadaacdf4886469d55 100644 (file)
@@ -298,6 +298,7 @@ $string['invalidscaleid'] = 'Incorrect scale id';
 $string['invalidsesskey'] = 'Incorrect sesskey submitted, form not accepted!';
 $string['invalidsection'] = 'Course module record contains invalid section';
 $string['invalidshortname'] = 'That\'s an invalid short course name';
+$string['invalidstatedetected'] = 'Something has gone wrong: $a. This should never normally happen.';
 $string['invalidurl'] = 'Invalid URL';
 $string['invaliduser'] = 'Invalid user';
 $string['invaliduserid'] = 'Invalid user id';
index 3e47966f98b47525bf5a61b6d281c8ee1b57c6c4..c0ca7b415ce50f90121c367d69c430569509e7c8 100644 (file)
@@ -45,10 +45,10 @@ class moodle_exception extends Exception {
 }
 
 /**
- * Exception indicating programming error, must be fixed by a programer.
+ * Exception indicating programming error, must be fixed by a programer. For example
+ * a core API might throw this type of exception if a plugin calls it incorrectly.
  */
 class coding_exception extends moodle_exception {
-
     /**
      * Constructor
      * @param string $hint short description of problem
@@ -59,6 +59,24 @@ class coding_exception extends moodle_exception {
     }
 }
 
+/**
+ * An exception that indicates something really weird happended. For example,
+ * if you do switch ($context->contextlevel), and have one case for each
+ * CONTEXT_... constant. You might throw an invalid_state_exception in the
+ * default case, to just in case something really weird is going on, and 
+ * $context->contextlevel is invalid - ratehr than ignoring this possibility.
+ */
+class invalid_state_exception extends moodle_exception {
+    /**
+     * Constructor
+     * @param string $hint short description of problem
+     * @param string $debuginfo optional more detailed information
+     */
+    function __construct($hint, $debuginfo=null) {
+        parent::__construct('invalidstatedetected', 'debug', '', $hint, $debuginfo);
+    }
+}
+
 /**
  * Default exception handler, uncought exceptions are equivalent to using print_error()
  */