summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/Context.php11
-rw-r--r--src/Exceptions/LoaderException.php38
3 files changed, 47 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6451eee..eb8c70e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## [Unreleased]
+* Use custom LoaderException for context loading errors.
+
## [4.1.9] - 2017-07-12
* Various code cleanups.
diff --git a/src/Context.php b/src/Context.php
index fd8d96a..67bd771 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -9,6 +9,8 @@
namespace PhpMyAdmin\SqlParser;
+use PhpMyAdmin\SqlParser\Exceptions\LoaderException;
+
/**
* Holds the configuration of the context that is currently used.
*
@@ -443,7 +445,7 @@ abstract class Context
* @param string $context name of the context or full class name that
* defines the context
*
- * @throws \Exception if the specified context doesn't exist
+ * @throws LoaderException if the specified context doesn't exist
*/
public static function load($context = '')
{
@@ -455,8 +457,9 @@ abstract class Context
$context = self::$contextPrefix . $context;
}
if (!class_exists($context)) {
- throw new \Exception(
- 'Specified context ("' . $context . '") does not exist.'
+ throw new LoaderException(
+ 'Specified context ("' . $context . '") does not exist.',
+ $context
);
}
self::$loadedContext = $context;
@@ -491,7 +494,7 @@ abstract class Context
try {
// Trying to load the new context.
static::load($context);
- } catch (\Exception $e) {
+ } catch (LoaderException $e) {
// If it didn't work, we are looking for a new one and skipping
// over to the next generation that will try the new context.
$context = preg_replace(
diff --git a/src/Exceptions/LoaderException.php b/src/Exceptions/LoaderException.php
new file mode 100644
index 0000000..4276e80
--- /dev/null
+++ b/src/Exceptions/LoaderException.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * Exception thrown by the lexer.
+ */
+
+namespace PhpMyAdmin\SqlParser\Exceptions;
+
+/**
+ * Exception thrown by the lexer.
+ *
+ * @category Exceptions
+ *
+ * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
+ */
+class LoaderException extends \Exception
+{
+ /**
+ * The failed load name.
+ *
+ * @var string
+ */
+ public $name;
+
+ /**
+ * Constructor.
+ *
+ * @param string $msg the message of this exception
+ * @param string $ch the character that produced this exception
+ * @param int $pos the position of the character
+ * @param int $code the code of this error
+ */
+ public function __construct($msg = '', $name = '', $code = 0)
+ {
+ parent::__construct($msg, $code);
+ $this->name = $name;
+ }
+}