Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.363
diff -u -r1.363 bootstrap.inc
--- includes/bootstrap.inc	17 Mar 2010 13:58:45 -0000	1.363
+++ includes/bootstrap.inc	18 Mar 2010 05:47:10 -0000
@@ -1842,7 +1842,23 @@
 function _drupal_exception_handler($exception) {
   require_once DRUPAL_ROOT . '/includes/errors.inc';
   // Log the message to the watchdog and return an error page to the user.
-  _drupal_log_error(_drupal_decode_exception($exception), TRUE);
+  
+  try {
+    _drupal_log_error(_drupal_decode_exception($exception), TRUE);
+  }
+  catch (Exception $exception2) {
+  
+    // Another uncaught exception was thrown while handling the first one.
+    // If we are displaying errors, then do so with no possibility of a further uncaught exception being thrown.
+  
+    $error_level = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL);
+    if ($error_level == ERROR_REPORTING_DISPLAY_ALL || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) {
+
+      print 'Additional uncaught exception thrown while handling exception.<br /><br />';
+      print '<b>Original</b><br />' . _drupal_render_exception_safe($exception) . '<br /><br />';
+      print '<b>Additional</b><br />' . _drupal_render_exception_safe($exception2) . '<br /><br />';
+    }
+  }
 }
 
 /**
@@ -2684,11 +2700,15 @@
     }
   }
   catch(Exception $exception) {
-    require_once DRUPAL_ROOT . '/includes/errors.inc';
-    // The theme has already been printed so it doesn't make much sense to use
-    // drupal_exception_handler() because that would display the maintenaince
-    // page below the usual page. For now, just print the error for debugging.
-    // @todo: Improve this.
-    print t('%type: %message in %function (line %line of %file).', _drupal_decode_exception($exception));
+    
+    // If we are displaying errors, then do so with no possibility of a further uncaught exception being thrown.
+
+    $error_level = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL);
+    if ($error_level == ERROR_REPORTING_DISPLAY_ALL || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) {
+
+      require_once DRUPAL_ROOT . '/includes/errors.inc';
+      print 'Uncaught exception thrown in shutdown function.<br /><br />';
+      print _drupal_render_exception_safe($exception) . '<br /><br />';
+    }
   }
 }
Index: includes/errors.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/errors.inc,v
retrieving revision 1.2
diff -u -r1.2 errors.inc
--- includes/errors.inc	6 Mar 2010 06:31:24 -0000	1.2
+++ includes/errors.inc	18 Mar 2010 05:47:10 -0000
@@ -87,7 +87,8 @@
  *
  * @param $exception
  *   The exception object that was thrown.
- * @return An error in the format expected by _drupal_log_error().
+ * @return
+ *   An error in the format expected by _drupal_log_error().
  */
 function _drupal_decode_exception($exception) {
   $message = $exception->getMessage();
@@ -126,6 +127,19 @@
 }
 
 /**
+ * Render an error message for an exception without any possibility of a further exception occuring.
+ *
+ * @param $exception
+ *   The exception object that was thrown.
+ * @return
+ *   An error message.
+ */
+function _drupal_render_exception_safe($exception) {
+
+  return strtr('%type: %message in %function (line %line of %file).', _drupal_decode_exception($exception));
+}
+
+/**
  * Log a PHP error or exception, display an error page in fatal cases.
  *
  * @param $error
@@ -163,13 +177,7 @@
     $number++;
   }
 
-  try {
-    watchdog('php', '%type: %message in %function (line %line of %file).', $error, $error['severity_level']);
-  }
-  catch (Exception $e) {
-    // Ignore any additional watchdog exception, as that probably means
-    // that the database was not initialized correctly.
-  }
+  watchdog('php', '%type: %message in %function (line %line of %file).', $error, $error['severity_level']);
 
   if ($fatal) {
     drupal_add_http_header('Status', '500 Service unavailable (with message)');
