Repack plain exceptions into a SystemException to benefit from its improvements.
authorTim Düsterhus <timwolla@arcor.de>
Fri, 3 Feb 2012 16:46:31 +0000 (17:46 +0100)
committerTim Düsterhus <timwolla@arcor.de>
Fri, 3 Feb 2012 16:52:06 +0000 (17:52 +0100)
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/exception/LoggedException.class.php
wcfsetup/install/files/lib/system/exception/SystemException.class.php

index a5dd3b07f2d76efbea1cdea17f95b54cdcbf223f..249deb0bb51323fff64fb0b6b53d2a9280d1a823 100644 (file)
@@ -238,8 +238,8 @@ class WCF {
                        exit;
                }
                
-               print $e;
-               exit;
+               // repack Exception
+               self::handleException(new exception\SystemException($e->getMessage(), $e->getCode(), '', $e));
        }
        
        /**
index b04573424c2698f5341fdcc9268c6c1737398e47..5e119ce080011849c68095a0fa18753042dba504 100644 (file)
@@ -14,6 +14,7 @@ use wcf\system\WCF;
  * @category   Community Framework
  */
 class LoggedException extends \Exception {
+       
        /**
         * Surpresses the original error message.
         * 
@@ -24,7 +25,8 @@ class LoggedException extends \Exception {
                        return 'An error occured. Sorry.';
                }
                
-               return $this->getMessage();
+               $e = ($this->getPrevious() ?: $this);
+               return $e->getMessage();
        }
        
        /**
@@ -47,8 +49,9 @@ class LoggedException extends \Exception {
                        return;
                }
                
+               $e = ($this->getPrevious() ?: $this);
                // build message
-               $message = date('r', TIME_NOW) . "\n" . $this->getMessage() . "\n\n" . $this->getTraceAsString() . "\n\n\n";
+               $message = date('r', TIME_NOW) . "\n" . $e->getMessage() . "\n\n" . $e->getTraceAsString() . "\n\n\n";
                
                // append
                @file_put_contents($logFile, $message, FILE_APPEND);
index cd2d68f9fe788f36c2d05fd37a00206f9e2be441..227f42014ee955c8d5ef01c448c7f672ed945eae 100644 (file)
@@ -38,9 +38,10 @@ class SystemException extends LoggedException implements IPrintableException {
         * @param       string          $message        error message
         * @param       integer         $code           error code
         * @param       string          $description    description of the error
+        * @param       \Exception      $previous       repacked Exception
         */
-       public function __construct($message = '', $code = 0, $description = '') {
-               parent::__construct($message, $code);
+       public function __construct($message = '', $code = 0, $description = '', \Exception $previous = null) {
+               parent::__construct($message, $code, $previous);
                $this->description = $description;
        }
        
@@ -58,7 +59,8 @@ class SystemException extends LoggedException implements IPrintableException {
         * @see \Exception::getTraceAsString()
         */
        public function __getTraceAsString() {
-               $string = preg_replace('/Database->__construct\(.*\)/', 'Database->__construct(...)', $this->getTraceAsString());
+               $e = ($this->getPrevious() ?: $this);
+               $string = preg_replace('/Database->__construct\(.*\)/', 'Database->__construct(...)', $e->getTraceAsString());
                $string = preg_replace('/mysqli->mysqli\(.*\)/', 'mysqli->mysqli(...)', $string);
                return $string;
        }
@@ -81,7 +83,7 @@ class SystemException extends LoggedException implements IPrintableException {
                
                // print report
                echo '<?xml version="1.0" encoding="UTF-8"?>';
-               
+               $e = ($this->getPrevious() ?: $this);
                ?>
 
                <!DOCTYPE html>
@@ -155,9 +157,9 @@ class SystemException extends LoggedException implements IPrintableException {
                                                        <h2>Information:</h2>
                                                        <p>
                                                                <b>error message:</b> <?php echo StringUtil::encodeHTML($this->_getMessage()); ?><br>
-                                                               <b>error code:</b> <?php echo intval($this->getCode()); ?><br>
+                                                               <b>error code:</b> <?php echo intval($e->getCode()); ?><br>
                                                                <?php echo $this->information; ?>
-                                                               <b>file:</b> <?php echo StringUtil::encodeHTML($this->getFile()); ?> (<?php echo $this->getLine(); ?>)<br>
+                                                               <b>file:</b> <?php echo StringUtil::encodeHTML($e->getFile()); ?> (<?php echo $e->getLine(); ?>)<br>
                                                                <b>php version:</b> <?php echo StringUtil::encodeHTML(phpversion()); ?><br>
                                                                <b>wcf version:</b> <?php echo WCF_VERSION; ?><br>
                                                                <b>date:</b> <?php echo gmdate('r'); ?><br>