Permalink
Browse files

let Fail promote chosen errors to ErrorExceptions

  • Loading branch information...
1 parent 1f604fb commit 4098b52db4fbb99f068264395288d0235ab69749 Brennen Bearnes committed Dec 18, 2012
Showing with 19 additions and 3 deletions.
  1. +19 −3 Fail.php
View
@@ -73,6 +73,17 @@ class Fail {
30719 => 'E_ALL',
);
+ /**
+ * List errors which should be promoted to exceptions.
+ *
+ * Something like:
+ *
+ * <code>
+ * \SparkLib\Fail::$exceptionOnErrors = array(E_RECOVERABLE_ERROR => true);
+ * </code>
+ */
+ public static $exceptionOnErrors = array();
+
/**
* Set up error & exception handling, logging, etc.
*
@@ -155,8 +166,7 @@ public static function handleError ($errno, $errstr, $errfile, $errline, $errcon
// Filter out low-urgency stuff we don't care about right now:
// XXX: Get rid of SFE-specific stuff here.
if ($errno === \E_NOTICE) {
- if (stristr($errstr, 'undefined index')) return;
- if (strstr($errfile, 'Test.php')) return;
+ if (stristr($errstr, 'undefined index')) return;
}
if ($errno === \E_DEPRECATED) {
if (strstr($errfile, 'Barcode.php')) return;
@@ -166,7 +176,7 @@ public static function handleError ($errno, $errstr, $errfile, $errline, $errcon
if (strstr($errfile, 'Code39.php')) return;
}
- $errorType = self::$errorList[(int)$errno];
+ $errorType = static::$errorList[(int)$errno];
self::log("{$errorType} - $errfile:$errline - $errstr\n");
@@ -177,6 +187,12 @@ public static function handleError ($errno, $errstr, $errfile, $errline, $errcon
self::log(static::compile_backtrace($trace));
}
+
+ if (isset(static::$exceptionOnErrors[ $errno ])) {
+ // these get thrown on type errors and possibly elsewhere - let's
+ // see what happens if we make sure they're fatal
+ throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
+ }
}
/**

0 comments on commit 4098b52

Please sign in to comment.