Attempt to catch exceptions before PHP goes full retard
authorAlexander Ebert <ebert@woltlab.com>
Tue, 4 Dec 2012 20:32:59 +0000 (21:32 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 4 Dec 2012 20:32:59 +0000 (21:32 +0100)
wcfsetup/install/files/lib/system/WCF.class.php

index bdd19f15e27095bcc1562d3394e5511550f035be..b7fa2463fd3c876ca800330e8ab1045b02a1adb9 100644 (file)
@@ -120,29 +120,34 @@ class WCF {
         * Flushs the output, closes caches and updates the session.
         */
        public static function destruct() {
-               // database has to be initialized
-               if (!is_object(self::$dbObj)) return;
-               
-               // flush output
-               if (ob_get_level() && ini_get('output_handler')) {
-                       ob_flush();
-               }
-               else {
-                       flush();
-               }
-               
-               // update session
-               if (is_object(self::getSession())) {
-                       self::getSession()->update();
+               try {
+                       // database has to be initialized
+                       if (!is_object(self::$dbObj)) return;
+                       
+                       // flush output
+                       if (ob_get_level() && ini_get('output_handler')) {
+                               ob_flush();
+                       }
+                       else {
+                               flush();
+                       }
+                       
+                       // update session
+                       if (is_object(self::getSession())) {
+                               self::getSession()->update();
+                       }
+                       
+                       // close cache source
+                       if (CacheHandler::isInitialized() && is_object(CacheHandler::getInstance()) && is_object(CacheHandler::getInstance()->getCacheSource())) {
+                               CacheHandler::getInstance()->getCacheSource()->close();
+                       }
+                       
+                       // execute shutdown actions of user storage handler
+                       UserStorageHandler::getInstance()->shutdown();
                }
-               
-               // close cache source
-               if (CacheHandler::isInitialized() && is_object(CacheHandler::getInstance()) && is_object(CacheHandler::getInstance()->getCacheSource())) {
-                       CacheHandler::getInstance()->getCacheSource()->close();
+               catch (\Exception $exception) {
+                       die("WCF::destruct() Unhandled exception: ".$exception->getMessage()."\n".base64_encode($exception->getTraceAsString()));
                }
-               
-               // execute shutdown actions of user storage handler
-               UserStorageHandler::getInstance()->shutdown();
        }
        
        /**
@@ -231,13 +236,18 @@ class WCF {
         * @param       \Exception      $e
         */
        public static final function handleException(\Exception $e) {
-               if ($e instanceof exception\IPrintableException) {
-                       $e->show();
-                       exit;
+               try {
+                       if ($e instanceof exception\IPrintableException) {
+                               $e->show();
+                               exit;
+                       }
+                       
+                       // repack Exception
+                       self::handleException(new exception\SystemException($e->getMessage(), $e->getCode(), '', $e));
+               }
+               catch (\Exception $exception) {
+                       die("WCF::handleException() Unhandled exception: ".$exception->getMessage()."\n".base64_encode($exception->getTraceAsString()));
                }
-               
-               // repack Exception
-               self::handleException(new exception\SystemException($e->getMessage(), $e->getCode(), '', $e));
        }
        
        /**