From: Gunnar Wrobel
Date: Tue, 26 Oct 2010 08:11:12 +0000 (+0200)
Subject: Add PEAR Error handler that converts the error into an exception and adds the PEAR...
X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=36e5a47332c4db59c861975880ebf1de00f5ddf8;p=horde.git
Add PEAR Error handler that converts the error into an exception and adds the PEAR Error stack trace to the exception message.
---
diff --git a/framework/Exception/lib/Horde/Exception/Pear.php b/framework/Exception/lib/Horde/Exception/Pear.php
new file mode 100644
index 000000000..e0d43b771
--- /dev/null
+++ b/framework/Exception/lib/Horde/Exception/Pear.php
@@ -0,0 +1,81 @@
+getMessage() . $this->_getPearTrace(),
+ $error->getCode()
+ );
+ }
+
+ /**
+ * Return a trace for the PEAR error.
+ *
+ * @param PEAR_Error $error The PEAR error.
+ *
+ * @return string The backtrace as a string.
+ */
+ private function _getPearTrace(PEAR_Error $error)
+ {
+ $backtrace = $error->getBacktrace();
+ if (!empty($backtrace)) {
+ $pear_error .= "\n\n" . 'PEAR Error:' . "\n";
+ foreach ($backtrace as $frame) {
+ $pear_error .= ' ' . $frame['class'] . '->'
+ . $frame['function'] . ' ' . $frame['file']
+ . ':' . $frame['line'] . "\n";
+ }
+ $pear_error .= "\n";
+ return $pear_error;
+ }
+ return '';
+ }
+
+ /**
+ * Exception handling.
+ *
+ * @param mixed $result The result to be checked for a PEAR_Error.
+ *
+ * @return mixed Returns the original result if it was no PEAR_Error.
+ *
+ * @throws Horde_Exception_Pear In case the result was a PEAR_Error.
+ */
+ static public function catchError($result)
+ {
+ if ($result instanceOf PEAR_Error) {
+ throw new self::$_class($result);
+ }
+ return $result;
+ }
+}
diff --git a/framework/Exception/package.xml b/framework/Exception/package.xml
index 9cab2c343..a73e321e4 100644
--- a/framework/Exception/package.xml
+++ b/framework/Exception/package.xml
@@ -1,5 +1,5 @@
-